Skip to content

Instantly share code, notes, and snippets.

@nanom1t
Forked from andelf/trc20.js
Created August 9, 2022 08:05
Show Gist options
  • Save nanom1t/8b96158406da13c9cb1beb671efb8680 to your computer and use it in GitHub Desktop.
Save nanom1t/8b96158406da13c9cb1beb671efb8680 to your computer and use it in GitHub Desktop.
Get TRC20 balance and transfer USDT tokens
const TronWeb = require('tronweb');
const HttpProvider = TronWeb.providers.HttpProvider;
const fullNode = new HttpProvider("https://api.trongrid.io");
// const fullNode = new HttpProvider("http://192.168.1.162:8090");
const solidityNode = new HttpProvider("https://api.trongrid.io");
const eventServer = new HttpProvider("https://api.trongrid.io");
const privateKey = "3481E79956D4BD95F358AC96D151C976392FC4E3FC132F78A847906DE588C145";
const tronWeb = new TronWeb(fullNode, solidityNode, eventServer, privateKey);
const CONTRACT = "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t";
const ACCOUNT = "TEQH6py1Pi8YHNgi9cPMHCKLboBTUZrsYT";
async function main() {
const {
abi
} = await tronWeb.trx.getContract(CONTRACT);
// console.log(JSON.stringify(abi));
const contract = tronWeb.contract(abi.entrys, CONTRACT);
const balance = await contract.methods.balanceOf(ACCOUNT).call();
console.log("balance:", balance.toString());
const resp = await contract.methods.transfer(ACCOUNT, 1000).send();
console.log("transfer:", resp);
}
main().then(() => {
console.log("ok");
})
.catch((err) => {
console.log("error:", err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment