-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransfer-egld.js
47 lines (38 loc) · 1.38 KB
/
transfer-egld.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import {
TransactionComputer,
Address,
TransactionsFactoryConfig,
TransferTransactionsFactory,
} from "@multiversx/sdk-core";
import {
receiverAddress,
syncAndGetAccount,
senderAddress,
getSigner,
apiNetworkProvider,
} from "./setup.js";
const makeTransfer = async () => {
const user = await syncAndGetAccount();
const computer = new TransactionComputer();
const signer = await getSigner();
// Prepare transfer transactions factory
const factoryConfig = new TransactionsFactoryConfig({ chainID: "D" });
const factory = new TransferTransactionsFactory({ config: factoryConfig });
// Transfer native EGLD token (value transfer, the same as with the simple transaction)
const egldTransaction = factory.createTransactionForNativeTokenTransfer({
sender: new Address(senderAddress),
receiver: new Address(receiverAddress),
// 0.01 EGLD (EGLD has 18 decimal places)
nativeAmount: BigInt("10000000000000000"),
});
egldTransaction.nonce = user.getNonceThenIncrement();
const serializedEgldTransaction =
computer.computeBytesForSigning(egldTransaction);
egldTransaction.signature = await signer.sign(serializedEgldTransaction);
const txHash = await apiNetworkProvider.sendTransaction(egldTransaction);
console.log(
"EGLD sent. Check in the Explorer: ",
`https://devnet-explorer.multiversx.com/transactions/${txHash}`
);
};
makeTransfer();