toncenter / tonweb

JavaScript SDK for TON (The Open Network)
MIT License
531 stars 152 forks source link

unpack account state #167

Open m1faridi opened 3 months ago

m1faridi commented 3 months ago

`const TonWeb = require('tonweb'); const tonMnemonic = require('tonweb-mnemonic'); const nacl = TonWeb.utils.nacl;

function hexToBytes(hex) { const bytes = []; for (let i = 0; i < hex.length; i += 2) { bytes.push(parseInt(hex.substr(i, 2), 16)); } return bytes; } const start = async () => { const tonweb = new TonWeb(new TonWeb.HttpProvider('https://toncenter.com/api/v2/jsonRPC', {apiKey: '6fbf6b53be0c5ef260ae69fa16c90ee7148c07792b3f3d6bec04056bea4374a9'}));

wallet = tonweb.wallet.create({address: 'EQC4vsrJdBzD0VffDldqw3xgCG25pCAsdOb8VmOHlsuc3c1R'}); // if your know only address at this moment

const address = await wallet.getAddress();

const seqno = await wallet.methods.seqno().call(); // call get-method seqno of wallet smart contract const hexSeed = '55983cda5ced5ebf66846d60da64c76c18c552aa63e23082ec3ee27d8f0aee8a'; const seed = new Uint8Array(hexToBytes(hexSeed)); const keyPair = nacl.sign.keyPair.fromSeed(seed);

const deploy = wallet.deploy(keyPair.secretKey); // deploy method

const deployFee = await deploy.estimateFee() // get estimate fee of deploy

const deploySended = await deploy.send() // deploy wallet contract to blockchain

const deployQuery = await deploy.getQuery(); // get deploy query Cell

// TRANSFER TON COINS

const transfer = wallet.methods.transfer({ secretKey: keyPair.secretKey, toAddress: 'EQDjVXa_oltdBP64Nc__p397xLCvGm2IcZ1ba7anSW0NAkeP', amount: TonWeb.utils.toNano('0.01'), // 0.01 TON seqno: seqno, payload: 'Hello', sendMode: 3, });

const transferFee = await transfer.estimateFee(); // get estimate fee of transfer

const transferSended = await transfer.send(); // send transfer query to blockchain

const transferQuery = await transfer.getQuery(); // get transfer query Cell

}

start().catch(error => console.error(error)); `

LITE_SERVER_UNKNOWN: cannot apply external message to current state : Failed to unpack account state