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

Outdated documentation / How to create a TON transfer? #71

Open
khelle opened this issue Nov 18, 2024 · 0 comments
Open

Outdated documentation / How to create a TON transfer? #71

khelle opened this issue Nov 18, 2024 · 0 comments

Comments

@khelle
Copy link

khelle commented Nov 18, 2024

I am trying to understand how to create w script that transfers TON using @ton/ton library, but I am unable to proceed.

Here's the code I am using:

    const nacl = require("tweetnacl");
    const { TonClient, WalletContractV4, internal } = require("@ton/ton");
    const { SendMode } = require("@ton/core");

    const client = new TonClient({
        endpoint: '', // endpoint
    });

    const senderSecret = ''; // private key in hex format

    const privBytes = Buffer.from(senderSecret, 'hex');
    const privUint8 = Uint8Array.from(privBytes);

    let keypair = nacl.sign.keyPair.fromSecretKey(privUint8);
    keypair.publicKey = Buffer.from(keypair.publicKey);
    keypair.secretKey = Buffer.from(keypair.secretKey);

    // Create wallet contract
    let workchain = 0; // Usually you need a workchain 0
    let wallet = WalletContractV4.create({ workchain, publicKey: keypair.publicKey });
    let contract = client.open(wallet);

    // Create a transfer
    let seqno = await contract.getSeqno();

    let transfer = await contract.createTransfer({
        seqno,
        messages: [internal({
            value: '0.1',
            to: 'UQDoxj63LWTBmCrVOxh2z_DAl1AxQ33Nbw9CTXWLPZDYIowF',
        })],
        secretKey: keypair.secretKey
    });

    let result = await contract.send(transfer);

I would expect this code to succeed, however all I am getting is:

error: 'LITE_SERVER_UNKNOWN: cannot apply external message to current state : External message was not accepted\n' +
        'Cannot run message on account: inbound external message rejected by transaction 3C44EF8316576398A14921538312C1A639F5637CAA6774614F7FB664837DB4AF:\n' +
        'exitcode=35, steps=31, gas_used=0\n' +
        'VM Log (truncated):\n' +
        '... XCPU s4,s3\n' +
        'execute EQUAL\n' +
        'execute THROWIFNOT 33\n' +
        'execute XCPU s5,s1\n' +
        'execute EQUAL\n' +
        'execute THROWIFNOT 34\n' +
        'execute XCHG s5\n' +
        'execute HASHSU\n' +
        'execute XC2PU s0,s6,s4\n' +
        'execute CHKSIGNU\n' +
        'execute THROWIFNOT 35\n' +
        'default exception handler, terminating vm with exit code 35\n',

The address from which I am sending this:

  • has balance of 5 TON so the balance should be enough
  • is uninitialized, but should not be a problem since contract.send() is supposed to attach initcode in that case

What am I missing?

@khelle khelle changed the title Oudated documentation / How to create a TON transfer? Outdated documentation / How to create a TON transfer? Nov 18, 2024
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