Created
July 18, 2019 10:42
-
-
Save thanhson1085/03e983e933dc9cbf7a3d5c88ef503b18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* RPC: https://rpc.tomochain.com mainnet, https://testnet.tomochain.com testnet | |
* chainId: 88 mainnet, 89 testnet | |
*/ | |
const Web3 = require('web3') | |
const rpc = 'https://testnet.tomochain.com' | |
const chainId = 89 | |
const pkey = 'YOUR_PKEY' // token holder pkey | |
const contractAddress = 'TOKEN_CONTRACT_ADDRESS' // token contract address | |
const web3 = new Web3(rpc) | |
const account = web3.eth.accounts.privateKeyToAccount(pkey) | |
const holder = account.address | |
web3.eth.accounts.wallet.add(account) | |
web3.eth.defaultAccount = holder | |
const trc21Abi = require('./TRC21.json') | |
const trc21 = new web3.eth.Contract(trc21Abi, | |
contractAddress, {gasPrice: 250000000, gas: 2000000 }) | |
// check token balance | |
trc21.methods.balanceOf(holder).call() | |
.then((result) => { | |
console.log(result) | |
}).catch(e => console.log(e)) | |
// Estimate fee for sending tokens | |
trc21.methods.estimateFee(250000000).call() | |
.then((result) => { | |
console.log(result) | |
}).catch(e => console.log(e)) | |
const to = '0xf8ac9d5022853c5847ef75aea0104eed09e5f402' // e.g send tokens to this address | |
// trasfer token to new address, make sure you have enough TOMO to pay tx fee | |
trc21.methods.transfer(to, '500000000000000000000').send({ | |
from: holder, | |
gas: 2000000, | |
gasPrice: 250000000, | |
chainId: chainId | |
}) | |
.then((result) => { | |
console.log(result) | |
}).catch(e => console.log(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment