tron - 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?
解决方案
推荐阅读
- apache-kafka - 包含 Kafka 消费者的服务的蓝/绿部署方法
- azure - Azure 逻辑应用按 SQL 排序
- numpy - 如何在动画共振振幅中正确改变共振频率?
- python - 如何使用 python 自动上传 Youtube
- php - Foreach 从一个数组访问数据
- javascript - 如何在清单 v3 Chrome 扩展程序中定期调用函数?
- java - Java 使用带有 javax.sound.sampled.Clip 的 mp3、ogg 和 wav 文件(或获取声音文件的比特率)
- sql - 基于变量有条件地检索数据
- java - 我为这个计划编写了一个程序,但我想知道程序是否有任何答案和我的写作不同?
- c# - C# 将联系人同步到 AD 的最佳方法