首页 > 解决方案 > Transfer trc20 usdt from one address to another

问题描述

I want to build a gateway for usdt payments and for this i'm using Tronweb tronWeb.utils.accounts.generateAccount() method I have generated an address, transfered 1 usdt to it and now i want to transfer the funds to another address. I get an error when sending the transaction:

  error: 'CONTRACT_VALIDATE_ERROR',
  message: 'contract validate error : account does not exist'


This is my code:

const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const privateKey = "c83f36ae2e8661170e798ca73181693b76d75af016666e6f6baad92f69cfa1e2";
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);
const trc20ContractAddress = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";//contract address
const addressTo = "TYcDSZor5ZgTsVMCZe1czfPEu8kzn6qe7L";
async function transfer() {
    try {
        const ownerAddress = tronWeb.address.fromPrivateKey(privateKey);
        const contractAddressHex = tronWeb.address.toHex(trc20ContractAddress);
        const contractInstance = await tronWeb.contract().at(contractAddressHex);
        const decimals = await contractInstance.decimals().call();
        const amount = 7 * Math.pow(10, decimals);
        const response = await contractInstance.transfer(addressTo, amount).send();
        console.log(response);
    } catch (e) {
        console.error(e);
        return null;`enter code here`
    }
}
transfer();

   
Is it something else i should do for getting this to work?

标签: trontronweb

解决方案


生成新帐户后,您需要通过将 TRX/TRC-10 令牌转移到该地址来激活它。

转移 TRC20 不会激活帐户。但是,可以通过地址向Tronscan查询余额。

波场账户文件


推荐阅读