Skip to content

Token Transfer Failed on TON Blockchain #324

@Deepakab56

Description

@Deepakab56

I am experiencing an issue when trying to send tokens using the TON blockchain. The transaction fails with an error code, and I am unable to determine the root cause. I have included relevant code snippets and transaction details below for further investigation.

import "@stdlib/ownable";
import "@stdlib/deploy";

message TransferRequest {
amount: Int as uint256;
toaddress: Address;
}

message Transfer {
to: Address;
amount: Int as uint256;
}

contract MyContract with Deployable {
jettonTokenAddress: Address;

init() {
    self.jettonTokenAddress = address("EQDdPVRDGzb5zT3xVVAEqUNqoOSiy6pd7WCB_YvDIoAFjDsI");
}

receive(msg: TransferRequest) {
    let tokenContract: Address = self.jettonTokenAddress;
    self.sendJettonTokens(tokenContract, msg.amount, msg.toaddress);
}

fun getJettonWalletInit(token: Address, address: Address): StateInit {
    return initOf JettonDefaultWallet(token, address);
}

fun sendJettonTokens(tokenAddress: Address, amount: Int, toaddr: Address) {
    let winit: StateInit = self.getJettonWalletInit(tokenAddress, toaddr);
    let walletAddress: Address = contractAddress(winit);

    let data: Cell = TokenTransferInternal{ 
        queryId: 0,
        amount: amount,
        from: myAddress(),
        response_destination: toaddr,
        forward_ton_amount: 0,
        forward_payload: emptySlice() 
    }.toCell();
    
    let body: Cell = TokenTransfer{
        queryId: 0,
        amount: amount,
        destination: toaddr,
        response_destination: toaddr,
        custom_payload: data,
        forward_ton_amount: 0,
        forward_payload: emptySlice()
    }.toCell();

    send(SendParameters{
        to: walletAddress,
        value: 0,
        bounce: false,
        mode: SendRemainingValue,
        body: body,
        code: winit.code,
        data: winit.data
    });
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions