i'm following tutorial here uses testrpc web3.js. after installing packages ethereumjs-testrpc
, web3
, testrpc
started gives 10 available accounts , private keys.
web3
@ 1.0.0-beta.18 , ethereumjs-testrpc
@ 4.1.1.
when following code run
web3 = require('web3'); web3 = new web3(new web3.providers.httpprovider("http://localhost:8545")); web3.eth.accounts
i following output instead of 10 accounts shown in tutorial. went wrong?
accounts { currentprovider: [getter/setter], _requestmanager: requestmanager { provider: httpprovider { host: 'http://localhost:8545', timeout: 0, connected: false }, providers: { websocketprovider: [function: websocketprovider], httpprovider: [function: httpprovider], ipcprovider: [function: ipcprovider] }, subscriptions: {} }, givenprovider: null, providers: { websocketprovider: [function: websocketprovider], httpprovider: [function: httpprovider], ipcprovider: [function: ipcprovider] }, _provider: httpprovider { host: 'http://localhost:8545', timeout: 0, connected: false }, setprovider: [function], _ethereumcall: { getid: { [function: send] method: [object], request: [function: bound ], call: 'net_version' }, getgasprice: { [function: send] method: [object], request: [function: bound ], call: 'eth_gasprice' }, gettransactioncount: { [function: send] method: [object], request: [function: bound ], call: 'eth_gettransactioncount' } }, wallet: wallet { length: 0, _accounts: [circular], defaultkeyname: 'web3js_wallet' } }
later in tutorial, web3.eth.accounts
needed when deploying contract
deployedcontract = votingcontract.new(['rama','nick','jose'], {data: bytecode, from: web3.eth.accounts[0], gas: 4700000})
that tutorial written before web3.js v1 came out. api has changed in v1, including eth.accounts
. can either pin older version of web3.js, 0.19.0
, or find equivalent method in new v1 docs.
retrieving accounts down asynchronously, many other calls in new api. can call callback or using promises. printing list of accounts console like:
web3.eth.getaccounts(console.log); // or web3.eth.getaccounts().then(console.log);
from web3.eth.getaccounts
v1 documentation
so rewriting section referenced @ end:
web3.eth.getaccounts() .then(function (accounts) { return votingcontract.new(['rama','nick','jose'], {data: bytecode, from: accounts[0], gas: 4700000}); }) .then(function (deployedcontract) { // whatever want deployedcontract... })
Comments
Post a Comment