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
| import Web3 from "web3" import Tx from "ethereumjs-tx"
let w3 = new Web3(new Web3.providers.HttpProvider("https://http-mainnet.hoosmartchain.com"));
const send_hoo = () => { w3.eth.getBalance("0x046DFD38e4eeB06073782e3DADFB8e56cAC360cE", ((error, balance) => { if (error) { return } console.log(balance);
w3.eth.getTransactionCount("0x046DFD38e4eeB06073782e3DADFB8e56cAC360cE", ((error, count) => { if (error) { return } console.log(count);
let rawTx = { from: '0x046DFD38e4eeB06073782e3DADFB8e56cAC360cE', to: '0x26b1724D9F6CA5DEe5DAA308f197dF7eafe4EB93', value: w3.utils.toHex(w3.utils.toWei('0.001', 'ether')), nonce: w3.utils.toHex(count), gasLimit: w3.utils.toHex(8000000), gasPrice: w3.utils.toHex(w3.utils.toWei('1', 'gwei')), }
let tx = new Tx(rawTx); tx.sign(new Buffer('985f728fccaf6****私钥', 'hex')); let serializedTx = tx.serialize(); let raw = '0x' + serializedTx.toString('hex') w3.eth.sendSignedTransaction(raw, (err, txHash) => { console.log('txHash:', txHash) console.log(err) }) })) })) }
send_hoo();
|