-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransfer-fungible.js
56 lines (47 loc) · 1.61 KB
/
transfer-fungible.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
48
49
50
51
52
53
54
55
56
import {
TransactionComputer,
Address,
TransactionsFactoryConfig,
TransferTransactionsFactory,
TokenTransfer,
Token,
} 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 fungibleTransaction = factory.createTransactionForESDTTokenTransfer({
sender: new Address(senderAddress),
receiver: new Address(receiverAddress),
tokenTransfers: [
new TokenTransfer({
token: new Token({ identifier: "DEMFUNGI-3ec13b" }),
// Send 10, remember about 18 decimal places
amount: BigInt("10000000000000000000"), // or 10000000000000000000n
}),
],
});
fungibleTransaction.nonce = user.getNonceThenIncrement();
const serializedfungibleTransaction =
computer.computeBytesForSigning(fungibleTransaction);
fungibleTransaction.signature = await signer.sign(
serializedfungibleTransaction
);
const txHash = await apiNetworkProvider.sendTransaction(fungibleTransaction);
console.log(
"Fungible ESDT sent. Check in the Explorer: ",
`https://devnet-explorer.multiversx.com/transactions/${txHash}`
);
};
makeTransfer();