我想使用 TronWeb 发送 trc20 令牌。我是否需要使用 contract().at() 来执行此操作?这是否意味着我需要将 trc20 代币视为智能合约?
问问题
561 次
2 回答
1
首先,澄清任何网络(不仅仅是tron)上的每个代币都有自己的智能合约,该合约已发布到网络
这是获取您的帐户余额的代码和另一个转移 USDT 的代码
不要忘记使用您的私钥和网络端点初始化代码
请注意,您需要 tron 能量和带宽来执行交易,您可以使用此链接了解它们
const CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t"
async function getBalance(account) {
const {
abi
} = await tronWeb.trx.getContract(CONTRACT);
const contract = tronWeb.contract(abi.entrys, CONTRACT);
const balance = await contract.methods.balanceOf(account).call();
console.log("balance:", balance.toString());
}
async function transferUSDT(destination, amount) {
const {
abi
} = await tronWeb.trx.getContract(CONTRACT);
const contract = tronWeb.contract(abi.entrys, CONTRACT);
const resp = await contract.methods.transfer(destination, amount).send();
console.log("transfer:", resp);
}
于 2022-02-17T13:57:52.307 回答
0
当您使用私钥初始化 tronweb 组件时,您可以使用 contract().at()
tronWeb = new TronWeb(
'https://api.nileex.io/',
'https://api.nileex.io/',
'https://event.nileex.io/',
'your privateKey'
);
于 2021-06-17T10:20:35.057 回答