var Tx = require('ethereumjs-tx').Transaction
const Web3 = require('web3') const web3 = new Web3('https://ropsten.infura.io/YOUR_INFURA_API_KEY')
Kevin@QIKEGU g:\qikegu\ethereum\web3js > node > web3.eth.accounts.create() Thrown: ReferenceError: web3 is not defined > const Web3 = require('web3') undefined > const web3 = new Web3('https://ropsten.infura.io/v3/YOUR_INFURA_API_KEY') undefined > web3.eth.accounts.create() { address: '0xf4Ab5314ee8d7AA0eB00b366c52cEEccC62d6B4B', privateKey: '0xb75e2bcaec74857cf9bb6636d66a04784d4c0fcfd908f4a2bc213428eba5af0d', signTransaction: [Function: signTransaction], sign: [Function: sign], encrypt: [Function: encrypt] } > web3.eth.accounts.create() { address: '0xff96B8B43ECd6C49805747F94747bFfa3A960b69', privateKey: '0xac0adfdbaeb0770a479e79aac78779d82fdc2f9262e0c8f751ae70fb63ef6196', signTransaction: [Function: signTransaction], sign: [Function: sign], encrypt: [Function: encrypt] } >
注意 如果上面地址失效,可以在google/bing中,搜索 “ropsten faucet”,查找能获取测试以太币的地方。
> SET PRIVATE_KEY_1='b75e2bcaec74857cf9bb6636d66a04784d4c0fcfd908f4a2bc213428eba5af0d' > SET PRIVATE_KEY_2='ac0adfdbaeb0770a479e79aac78779d82fdc2f9262e0c8f751ae70fb63ef6196'
$ export PRIVATE_KEY_1='b75e2bcaec74857cf9bb6636d66a04784d4c0fcfd908f4a2bc213428eba5af0d' $ export PRIVATE_KEY_2='ac0adfdbaeb0770a479e79aac78779d82fdc2f9262e0c8f751ae70fb63ef6196'
const account1 = '0xf4Ab5314ee8d7AA0eB00b366c52cEEccC62d6B4B' const account2 = '0xff96B8B43ECd6C49805747F94747bFfa3A960b69'
const privateKey1 = process.env.PRIVATE_KEY_1 const privateKey2 = process.env.PRIVATE_KEY_2
const privateKey1 = Buffer.from(process.env.PRIVATE_KEY_1) const privateKey1 = Buffer.from(process.env.PRIVATE_KEY_2)