|
| 1 | +import { |
| 2 | + TransactionComputer, |
| 3 | + Address, |
| 4 | + TransactionsFactoryConfig, |
| 5 | + TransferTransactionsFactory, |
| 6 | + TokenTransfer, |
| 7 | + Token, |
| 8 | +} from "@multiversx/sdk-core"; |
| 9 | +import { |
| 10 | + receiverAddress, |
| 11 | + syncAndGetAccount, |
| 12 | + senderAddress, |
| 13 | + getSigner, |
| 14 | + apiNetworkProvider, |
| 15 | +} from "./setup.js"; |
| 16 | + |
| 17 | +const makeTransfer = async () => { |
| 18 | + const user = await syncAndGetAccount(); |
| 19 | + const computer = new TransactionComputer(); |
| 20 | + const signer = await getSigner(); |
| 21 | + |
| 22 | + // Prepare transfer transactions factory |
| 23 | + const factoryConfig = new TransactionsFactoryConfig({ chainID: "D" }); |
| 24 | + const factory = new TransferTransactionsFactory({ config: factoryConfig }); |
| 25 | + |
| 26 | + // Transfer native EGLD token (value transfer, the same as with the simple transaction) |
| 27 | + const multiTransferTransaction = |
| 28 | + factory.createTransactionForESDTTokenTransfer({ |
| 29 | + sender: new Address(senderAddress), |
| 30 | + receiver: new Address(receiverAddress), |
| 31 | + tokenTransfers: [ |
| 32 | + new TokenTransfer({ |
| 33 | + token: new Token({ |
| 34 | + identifier: "ELVNFACE-762e9d", |
| 35 | + nonce: BigInt("90"), |
| 36 | + }), |
| 37 | + // Send 1, it is always 1 for NFTs |
| 38 | + amount: BigInt("1"), // or 1n |
| 39 | + }), |
| 40 | + new TokenTransfer({ |
| 41 | + token: new Token({ identifier: "DEMSFT-00eac9", nonce: BigInt("1") }), |
| 42 | + // Send 10 |
| 43 | + amount: BigInt("10"), // or 10n |
| 44 | + }), |
| 45 | + new TokenTransfer({ |
| 46 | + token: new Token({ identifier: "DEMFUNGI-3ec13b" }), |
| 47 | + // Send 10, remember about 18 decimal places |
| 48 | + amount: BigInt("10000000000000000000"), // or 10000000000000000000n |
| 49 | + }), |
| 50 | + ], |
| 51 | + }); |
| 52 | + |
| 53 | + multiTransferTransaction.nonce = user.getNonceThenIncrement(); |
| 54 | + |
| 55 | + const serializedmultiTransferTransaction = computer.computeBytesForSigning( |
| 56 | + multiTransferTransaction |
| 57 | + ); |
| 58 | + |
| 59 | + multiTransferTransaction.signature = await signer.sign( |
| 60 | + serializedmultiTransferTransaction |
| 61 | + ); |
| 62 | + |
| 63 | + const txHash = await apiNetworkProvider.sendTransaction( |
| 64 | + multiTransferTransaction |
| 65 | + ); |
| 66 | + |
| 67 | + console.log( |
| 68 | + "Multiple ESDTs sent. Check in the Explorer: ", |
| 69 | + `https://devnet-explorer.multiversx.com/transactions/${txHash}` |
| 70 | + ); |
| 71 | +}; |
| 72 | + |
| 73 | +makeTransfer(); |
0 commit comments