Skip to content

Instantly share code, notes, and snippets.

@andelf
Created April 20, 2020 07:12
Show Gist options
  • Select an option

  • Save andelf/bdd18734d40774a721d0c4cbcec67037 to your computer and use it in GitHub Desktop.

Select an option

Save andelf/bdd18734d40774a721d0c4cbcec67037 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);
});
@tshanchuan
Copy link
Copy Markdown

{ error: 'CONTRACT_VALIDATE_ERROR', message: 'contract validate error : account does not exist' }
也是contract.transfer()方法,请教下这个问题怎么解决?

@andelf
Copy link
Copy Markdown
Author

andelf commented Oct 28, 2020

@tshanchuan 你需要一个在链上激活的帐号。且有USDT余额

@epiphyllum
Copy link
Copy Markdown

@tshanchuan 你需要一个在链上激活的帐号。且有USDT余额
如何激活账号呢?

@rpr8588
Copy link
Copy Markdown

rpr8588 commented Feb 19, 2021

@andelf I am trying to transfer the amount in USDT, but I am getting the below error.
{ error: 'CONTRACT_VALIDATE_ERROR', message: 'contract validate error : account does not exist' }

**Note: I am using the above code to transfer the amount

Image 3

Note: I am using the above code to transfer the amountNote: I am using the above code to transfer the amount**

@thongtd
Copy link
Copy Markdown

thongtd commented Apr 30, 2021

Any update on this issue. I got the same issue when trying to send token TRC20 (USDT)

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

@thongtd
Copy link
Copy Markdown

thongtd commented Apr 30, 2021

I found the reason. I got this error because I don't have TRX on my wallet to pay the GAS fee.

@ehsanshojaeiiii
Copy link
Copy Markdown

is this for trc20 tx??any idea ??tnx

@andelf
Copy link
Copy Markdown
Author

andelf commented May 2, 2021

@ehsanshojaeiiii
Copy link
Copy Markdown

@andelf
tnx
please help me,i want to subscribe addresses , do you know any api or any thing else?

@utgpay2
Copy link
Copy Markdown

utgpay2 commented Jul 12, 2021

@andelf
tnx
please help me,i want to subscribe addresses , do you know any api or any thing else?
You can look at this USDT TRC20 API website https://www.token188.com. After setting the address that needs to be subscribed in his background, you can receive a notification of successful transfer.

@volevol
Copy link
Copy Markdown

volevol commented Mar 2, 2022

thank you very much

@sc0Vu
Copy link
Copy Markdown

sc0Vu commented May 1, 2022

@Nikhil05711
Copy link
Copy Markdown

i have trc20 still facing the same issue

@netwallettech
Copy link
Copy Markdown

i have trc20 still facing the same issue

same problem here. I have $15 on my address and same error. any ideas?

@netwallettech
Copy link
Copy Markdown

guys there is a solution. YOU MUST fund your address with TRX! not USDT TRC20. ONLY TRX.

read it here https://medium.com/tron-foundation/tron-developer-guide-account-2446633a750

@phpmac
Copy link
Copy Markdown

phpmac commented Oct 1, 2022

@banlieu451
Copy link
Copy Markdown

Simple rules of blockchains

if you do any transaction in a blockchain you need paid gas fees for any Tx, with each blockchain coin example :

  • Need TRX, in your wallet, if you submit Tx in Blockchain TRON

  • Need BNB if you .. in Blockchain BINANCE

  • Need ETH if you send SHIBA INU in Blockchain ETHEREUM

  • For send fund from a blockchain to another (CROSSCHAIN) you need use BRIDGE in some DEXs, example :

  • Transfer ETHEREUM to BINANCE CHAIN you need use bridge from UNISWAP example...

@marindev1991
Copy link
Copy Markdown

Hello, you are using private key.
But I want to send trx and trc20 with TronLink wallet.
What s the solution ?
It s not able to find it for me.

@blazeur001
Copy link
Copy Markdown

Hello, it's still working. Can someone help me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment