export declare interface SendTransactionRequest { /** * Sending transaction deadline in unix epoch seconds. */ validUntil: number; /** * The network (mainnet or testnet) where DApp intends to send the transaction. If not set, the transaction is sent to the network currently set in the wallet, but this is not safe and DApp should always strive to set the network. If the network parameter is set, but the wallet has a different network set, the wallet should show an alert and DO NOT ALLOW TO SEND this transaction. */ network?: CHAIN; /** * The sender address in '<wc>:<hex>' format from which DApp intends to send the transaction. Current account.address by default. */ from?: string; /** * Messages to send: min is 1, max is 4. */ messages: { /** * Receiver's address. */ address: string; /** * Amount to send in nanoTon. */ amount: string; /** * Contract specific data to add to the transaction. */ stateInit?: string; /** * Contract specific data to add to the transaction. */ payload?: string; }[]; }
所以當我今天想要做一筆簡單的傳送交易時,我只需要構建下列的交易參數即可
1 2 3 4 5 6 7 8 9 10 11
const transaction = { // The transaction is valid for 10 minutes from now, in unix epoch seconds. validUntil: Math.floor(Date.now() / 1000) + 600, messages: [ { address: "0:412410771DA82CBA306A55FA9E0D43C9D245E38133CB58F1457DFB8D5CD8892F", // destination address amount: "20000000", //Toncoin in nanotons }, ], };
const body = beginCell() .storeUint(0, 32) // write 32 zero bits to indicate that a text comment will follow .storeStringTail("Hello, TON!") // write our text comment .endCell();
const transaction = { // The transaction is valid for 10 minutes from now, in unix epoch seconds. validUntil: Math.floor(Date.now() / 1000) + 600, messages: [ { address: "0:412410771DA82CBA306A55FA9E0D43C9D245E38133CB58F1457DFB8D5CD8892F", // destination address amount: "20000000", //Toncoin in nanotons, payload: body.toBoc().toString("base64"), // payload with comment in body }, ], };