Last active
July 30, 2017 19:25
-
-
Save benjaminion/277d89e8e383237d758772bd985a0e7e to your computer and use it in GitHub Desktop.
Demo code for web3.js error message
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Web3 = require('web3'); | |
var net = require('net'); | |
//var web3 = new Web3('http://localhost:8545'); | |
var web3 = new Web3(new Web3.providers.IpcProvider('/tmp/testeth/geth.ipc', net)); | |
var params = { | |
sealEngine: 'NoProof', | |
options: {}, | |
params: { | |
accountStartNonce: '0x', | |
maximumExtraDataSize: '0x1000000', | |
blockReward: '0x', | |
allowFutureBlocks: '1', | |
homsteadForkBlock: '0x', | |
EIP150ForkBlock: '0x', | |
EIP158ForkBlock: '0x' | |
}, | |
genesis: { | |
author: '0000000000000010000000000000000000000000', | |
timestamp: '0x00', | |
parentHash: '0x0000000000000000000000000000000000000000000000000000000000000000', | |
extraData: '0x', | |
gasLimit: '0x1000000000000' | |
}, | |
accounts: { | |
'0000000000000000000000000000000000000001': { 'wei': '1', 'precompiled': { 'name': 'ecrecover', 'linear': { 'base': 3000, 'word': 0 } } }, | |
'0000000000000000000000000000000000000002': { 'wei': '1', 'precompiled': { 'name': 'sha256', 'linear': { 'base': 60, 'word': 12 } } }, | |
'0000000000000000000000000000000000000003': { 'wei': '1', 'precompiled': { 'name': 'ripemd160', 'linear': { 'base': 600, 'word': 120 } } }, | |
'0000000000000000000000000000000000000004': { 'wei': '1', 'precompiled': { 'name': 'identity', 'linear': { 'base': 15, 'word': 3 } } }, | |
} | |
}; | |
web3.extend( | |
{ | |
property: 'test', | |
methods: [ | |
{ | |
name: 'setChainParams', | |
call: 'test_setChainParams', | |
params: 1, | |
outputFormatter: web3.extend.formatters.formatOutputBool | |
}, | |
{ | |
name: 'mineBlocks', | |
call: 'test_mineBlocks', | |
params: 1, | |
inputFormatter: web3.extend.utils.formatInputInt, | |
outputFormatter: web3.extend.formatters.formatOutputBool | |
}] | |
} | |
); | |
Promise.all([ | |
web3.eth.personal.newAccount('password'), | |
web3.eth.personal.newAccount('password') | |
]).then(setupAccounts); | |
var acct0, acct1; | |
function setupAccounts(x) | |
{ | |
web3.eth.getAccounts() | |
.then(function(accountList){ | |
acct0 = accountList[0]; | |
acct1 = accountList[1]; | |
}) | |
.then(setupChain); | |
} | |
function setupChain() | |
{ | |
console.log("ACCT0 = ", acct0); | |
console.log("ACCT1 = ", acct1); | |
params.accounts[acct0] = { wei: '1606938044258990275541962092341162602522202993782792835301375'}; | |
web3.test.setChainParams(params) | |
.then(function(x) { | |
web3.eth.getBalance(acct0).then(console.log); | |
web3.eth.getBalance(acct1).then(console.log); | |
web3.eth.personal.unlockAccount(acct0, 'password', 100000) | |
.then(function(x){ | |
web3.eth.sendTransaction({from: acct0, to: acct1, value:1000}).then(console.log) | |
.then(console.log) | |
.catch(console.error) | |
}); | |
web3.test.mineBlocks(10); | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment