-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtransfer-sft.js
61 lines (52 loc) · 1.63 KB
/
transfer-sft.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
57
58
59
60
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();