diff --git a/multi-transfer.js b/multi-transfer.js new file mode 100644 index 0000000..7fbf445 --- /dev/null +++ b/multi-transfer.js @@ -0,0 +1,73 @@ +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 multiTransferTransaction = + factory.createTransactionForESDTTokenTransfer({ + sender: new Address(senderAddress), + receiver: new Address(receiverAddress), + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: "ELVNFACE-762e9d", + nonce: BigInt("90"), + }), + // Send 1, it is always 1 for NFTs + amount: BigInt("1"), // or 1n + }), + new TokenTransfer({ + token: new Token({ identifier: "DEMSFT-00eac9", nonce: BigInt("1") }), + // Send 10 + amount: BigInt("10"), // or 10n + }), + new TokenTransfer({ + token: new Token({ identifier: "DEMFUNGI-3ec13b" }), + // Send 10, remember about 18 decimal places + amount: BigInt("10000000000000000000"), // or 10000000000000000000n + }), + ], + }); + + multiTransferTransaction.nonce = user.getNonceThenIncrement(); + + const serializedmultiTransferTransaction = computer.computeBytesForSigning( + multiTransferTransaction + ); + + multiTransferTransaction.signature = await signer.sign( + serializedmultiTransferTransaction + ); + + const txHash = await apiNetworkProvider.sendTransaction( + multiTransferTransaction + ); + + console.log( + "Multiple ESDTs sent. Check in the Explorer: ", + `https://devnet-explorer.multiversx.com/transactions/${txHash}` + ); +}; + +makeTransfer(); diff --git a/transfer-egld.js b/transfer-egld.js new file mode 100644 index 0000000..7fbb255 --- /dev/null +++ b/transfer-egld.js @@ -0,0 +1,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(); diff --git a/transfer-fungible.js b/transfer-fungible.js new file mode 100644 index 0000000..5c4c3c7 --- /dev/null +++ b/transfer-fungible.js @@ -0,0 +1,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(); diff --git a/transfer-nft.js b/transfer-nft.js new file mode 100644 index 0000000..1b5f14c --- /dev/null +++ b/transfer-nft.js @@ -0,0 +1,62 @@ +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 nonFungibleTransaction = factory.createTransactionForESDTTokenTransfer({ + sender: new Address(senderAddress), + receiver: new Address(receiverAddress), + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ + identifier: "ELVNFACE-762e9d", + nonce: BigInt("86"), + }), + // Send 1, it is always 1 for NFTs + amount: BigInt("1"), // or 1n + }), + ], + }); + + nonFungibleTransaction.nonce = user.getNonceThenIncrement(); + + const serializednonFungibleTransaction = computer.computeBytesForSigning( + nonFungibleTransaction + ); + + nonFungibleTransaction.signature = await signer.sign( + serializednonFungibleTransaction + ); + + const txHash = await apiNetworkProvider.sendTransaction( + nonFungibleTransaction + ); + + console.log( + "Semi-fungible ESDT sent. Check in the Explorer: ", + `https://devnet-explorer.multiversx.com/transactions/${txHash}` + ); +}; + +makeTransfer(); diff --git a/transfer-sft.js b/transfer-sft.js new file mode 100644 index 0000000..3d1bec1 --- /dev/null +++ b/transfer-sft.js @@ -0,0 +1,61 @@ +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 semiFungibleTransaction = factory.createTransactionForESDTTokenTransfer( + { + sender: new Address(senderAddress), + receiver: new Address(receiverAddress), + tokenTransfers: [ + new TokenTransfer({ + token: new Token({ identifier: "DEMSFT-00eac9", nonce: BigInt("1") }), + // Send 10 + amount: BigInt("10"), // or 10n + }), + ], + } + ); + + semiFungibleTransaction.nonce = user.getNonceThenIncrement(); + + const serializedsemiFungibleTransaction = computer.computeBytesForSigning( + semiFungibleTransaction + ); + + semiFungibleTransaction.signature = await signer.sign( + serializedsemiFungibleTransaction + ); + + const txHash = await apiNetworkProvider.sendTransaction( + semiFungibleTransaction + ); + + console.log( + "Semi-fungible ESDT sent. Check in the Explorer: ", + `https://devnet-explorer.multiversx.com/transactions/${txHash}` + ); +}; + +makeTransfer();