Jetton transfer with @ton/ton and @tonconnect/react-ui
from Emre Aslan

How should we write code if we want to transfer Jetton with a wallet already connected with tonconnect-ui? I connectted wallet and I want to send Jetton to another person/wallet receiver address. But I get two unusual error.

First error in my tx body:

const body = beginCell()
.storeUint(0xf8a7ea5, 32)
.storeUint(0, 64)
.storeCoins(10000000)
.storeAddress(Address.parse(userFriendlyAddress))
.storeAddress(Address.parse(receiver_address))
.storeUint(0, 1))
.storeCoins(50000000)
.storeUInt(0, 1) // ------this line is error line.--------
.endCell();

If I make comment line, error is goes.But this is not a solution.

Uncaught (in promise) TypeError: (0 , tontonWEBPACK_IMPORTED_MODULE_7.beginCell)(...).storeUint(...).storeUint(...).storeCoins(...).storeAddress(...).storeAddress(...).storeUint(...).storeCoins(...).storeUInt is not a function


Second Error: If I make I get Failed to calculated fee on browser wallet



const userFriendlyAddress = useTonAddress();
const rawAddress = useTonAddress(false);
const wallet = useTonWallet();
const tonConnectUI, setOptions = useTonConnectUI();

const jettonAddress = "EQDEPcKFlXaKddKJVUvq2Rfn2QgH7MyFHxZek99FdMyq8XD";
const receiveraddress = "UQA76t6NCey61qBTkqosAs65sSrX2jIk9BloVz3NU76yYMap";

console.log("Address parse::", Address.parse(receiveraddress));
console.log("Address parseFriendly::", Address.parseFriendly(receiveraddress));
// console.log("Address parseRaw::", Address.parseRaw(receiveraddress));
const client = new TonClient({
endpoint: "https://toncenter.com/api/v2/jsonRPC",
apiKey: "myapikey",
});

const jettonTransfer = async () => {
let myTransaction;
if (userFriendlyAddress) {

const body = beginCell()
.storeUint(0xf8a7ea5, 32) // jetton transfer op code
.storeUint(0, 64) // queryid:uint64
.storeCoins(10000000) // amount:(VarUInteger 16) - Jetton amount for transfer (decimals = 6 - jUSDT, 9 - default)
.storeAddress(Address.parse(userFriendlyAddress)) // destination:MsgAddress
.storeAddress(Address.parse(receiveraddress)) // responsedestination:MsgAddress
.storeUint(0, 1) // custompayload:(Maybe ^Cell)
.storeCoins(50000000) // forwardtonamount:(VarUInteger 16)
.storeUInt(0, 1) // forwardpayload:(Either Cell ^Cell)
.endCell();
myTransaction = {
validUntil: Math.floor(Date.now() / 1000) + 360,
messages:
{
address: Address.parse(jettonAddress), // sender jetton wallet
amount: 100000000, // for commission fees, excess will be returned
payload: body.toBoc().toString("base64"), // payload with jetton transfer body
},
,
};
}
try {
tonConnectUI.sendTransaction(myTransaction);
} catch (error) {
alert(error);
}
};

šŸ”— Answer on TON Overflow

Oct 29, 2023, 1:39 PM

Ā© 2024 Draquery.com All rights reserved.