Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Token Transfer Failed on TON Blockchain #324

Open
Deepakab56 opened this issue Aug 12, 2024 · 0 comments
Open

Token Transfer Failed on TON Blockchain #324

Deepakab56 opened this issue Aug 12, 2024 · 0 comments

Comments

@Deepakab56
Copy link

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
    });
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant