-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtoken.js
82 lines (69 loc) · 2.04 KB
/
token.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
require('dotenv').config()
const Web3 = require('web3')
const Tx = require('ethereumjs-tx')
let tokenAddress = '0x0000000000000000000000000' // Contract address
let toAddress = '0x0000000000000000000000000000' // where to send it
let fromAddress = '0x00000000000000000000000000' // your wallet
let privateKey = Buffer.from (process.env.wallet_pass, 'hex')
const mysql = require('mysql2');
const pool = mysql.createPool({
host: process.env.db_host,
user: process.env.db_user,
database: process.env.db_name,
password: process.env.db_pass,
waitForConnections: true,
connectionLimit: 10,
queueLimit: 0
});
pool .execute(
'SELECT * FROM table WHERE name = ? AND age > ?',
['Rick C-137', 53],
function(err, results, fields) {
console.log(results);
console.log(fields);
}
);
const Web3js = new Web3(new Web3.providers.HttpProvider('https://data-seed-prebsc-1-s1.binance.org:8545'))
let contractABI = [
// transfer
{
'constant': false,
'inputs': [
{
'name': '_to',
'type': 'address'
},
{
'name': '_value',
'type': 'uint256'
}
],
'name': 'transfer',
'outputs': [
{
'name': '',
'type': 'bool'
}
],
'type': 'function'
}
]
let contract = new Web3js.eth.Contract(contractABI, tokenAddress, {from: fromAddress})
// 1e18 === 1 HST
let amount = Web3js.utils.toHex(5e18)
Web3js.eth.getTransactionCount(fromAddress)
.then((count) => {
let rawTransaction = {
'from': fromAddress,
'gasPrice': Web3js.utils.toHex(20 * 1e9),
'gasLimit': Web3js.utils.toHex(210000),
'to': tokenAddress,
'value': 0x0,
'data': contract.methods.transfer(toAddress, amount).encodeABI(),
'nonce': Web3js.utils.toHex(count)
}
let transaction = new Tx(rawTransaction)
transaction.sign(privateKey)
Web3js.eth.sendSignedTransaction('0x' + transaction.serialize().toString('hex'))
.on('transactionHash', console.log)
})