-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
548ad5d
commit e1bbfb5
Showing
5 changed files
with
299 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); |