3.How to do token transfer
Install dotenv, then make a .env file under your project src folder.
1
RPC_URL=HTTP://127.0.0.1:7545
2
MNEMONIC= # fill your nmemonic
Copied!

Transfer Native Token example

1
const dotenv = require('dotenv');
2
dotenv.config();
3
const w = require('../utils/wallet');
4
const Transaction = require('../utils/transfer');
5
const TokenERC20 = require('../utils/tokenERC20');
6
const IERC20 = require('../abi/IERC20.json');
7
8
const RPC_URL = process.env.RPC_URL;
9
const MNEMONIC = process.env.MNEMONIC;
10
const ERC20_ABI = process.env.ERC20_ABI;
11
12
console.log(`Your RPC_URL is ${RPC_URL}`);
13
console.log(`Your MNEMONIC is ${MNEMONIC}`);
14
15
const erc20 = JSON.parse(ERC20_ABI)
16
17
w.importAccountFromMnemonic(MNEMONIC);
18
console.log(`Your PrivateKey is ${w.getSelectedAccountPrivateKey()}`);
19
20
var transaction = new Transaction(RPC_URL, w.getSelectedAccountPrivateKey());
21
22
const test_send = async () => {
23
const tx = await transaction.send("0xd0c17D06dBC69c43D752EAeeFd1b3EDCA5a21d15",0.01)
24
console.log(tx);
25
}
26
27
test_send()
Copied!

Transfer BEP20 Token

1
var tokenERC20 = new TokenERC20(RPC_URL, w.getSelectedAccountPrivateKey(), IERC20.abi, "0x2f01C1d3a504d1bEA1a2C19E7B49D862b8D2cA5a");
2
3
const test_getBalance = async () => {
4
const balance = await transaction.getBalance(transaction.getAddress());
5
console.log(balance);
6
}
7
8
test_getBalance()
Copied!