mirror of https://github.com/hyperledger/besu
update and fix example scripts doc page and mkdocs (#1533)
- update node scripts to be able to include them from real source that we will be able to test (next step to do). - new scripts are more user friendly. - add package.json for npm management of dependencies - update doc page - update mkdocs guide for potential issue on pip version with Python3 - update mkdocs-material theme (only bug fixes) Signed-off-by: Adrian Sutton <adrian.sutton@consensys.net>pull/2/head
parent
d70453c43e
commit
a9bff931a5
@ -0,0 +1,2 @@ |
|||||||
|
node_modules |
||||||
|
package-lock.json |
@ -0,0 +1,76 @@ |
|||||||
|
const Web3 = require('web3') |
||||||
|
const ethTx = require('ethereumjs-tx') |
||||||
|
const readline = require('readline'); |
||||||
|
|
||||||
|
async function askQuestion(query) { |
||||||
|
const rl = readline.createInterface({ |
||||||
|
input: process.stdin, |
||||||
|
output: process.stdout, |
||||||
|
}); |
||||||
|
|
||||||
|
return new Promise(resolve => rl.question(query, ans => { |
||||||
|
rl.close(); |
||||||
|
resolve(ans); |
||||||
|
})) |
||||||
|
} |
||||||
|
|
||||||
|
const args = process.argv.slice(2); |
||||||
|
|
||||||
|
// web3 initialization - must point to the HTTP JSON-RPC endpoint
|
||||||
|
var provider = args[0] || 'http://localhost:8545'; |
||||||
|
console.log("******************************************"); |
||||||
|
console.log("Using provider : " + provider); |
||||||
|
console.log("******************************************"); |
||||||
|
var web3 = new Web3(new Web3.providers.HttpProvider(provider)) |
||||||
|
web3.transactionConfirmationBlocks = 1; |
||||||
|
// Sender address and private key
|
||||||
|
// Second acccount in dev.json genesis file
|
||||||
|
// Exclude 0x at the beginning of the private key
|
||||||
|
const addressFrom = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57' |
||||||
|
const privKey = Buffer.from('c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3', 'hex') |
||||||
|
|
||||||
|
// hexadecimal encoded compiled contract code
|
||||||
|
const contractData = '0x608060405234801561001057600080fd5b5060dc8061001f6000396000f3006080604052600436106049576000357c0100000000000000000000000000000000000000000000000000000000900463ffffffff1680633fa4f24514604e57806355241077146076575b600080fd5b348015605957600080fd5b50606060a0565b6040518082815260200191505060405180910390f35b348015608157600080fd5b50609e6004803603810190808035906020019092919050505060a6565b005b60005481565b80600081905550505600a165627a7a723058202bdbba2e694dba8fff33d9d0976df580f57bff0a40e25a46c398f8063b4c00360029' |
||||||
|
|
||||||
|
// Get the address transaction count in order to specify the correct nonce
|
||||||
|
web3.eth.getTransactionCount(addressFrom, "pending").then((txnCount) => { |
||||||
|
// Create the contract creation transaction object
|
||||||
|
var txObject = { |
||||||
|
nonce: web3.utils.toHex(txnCount), |
||||||
|
gasPrice: web3.utils.toHex(1000), |
||||||
|
gasLimit: web3.utils.toHex(126165), |
||||||
|
data: contractData |
||||||
|
}; |
||||||
|
|
||||||
|
// Sign the transaction with the private key
|
||||||
|
var tx = new ethTx(txObject); |
||||||
|
tx.sign(privKey) |
||||||
|
|
||||||
|
//Convert to raw transaction string
|
||||||
|
var serializedTx = tx.serialize(); |
||||||
|
var rawTxHex = '0x' + serializedTx.toString('hex'); |
||||||
|
|
||||||
|
// log raw transaction data to the console so you can send it manually
|
||||||
|
console.log("Raw transaction data: " + rawTxHex); |
||||||
|
|
||||||
|
// but also ask you if you want to send this transaction directly using web3
|
||||||
|
(async() => { |
||||||
|
const ans = await askQuestion("******************************************\n\ |
||||||
|
Do you want to send the signed contract creation transaction now ? (Y/N):"); |
||||||
|
if("y" == ans || "Y" == ans){ |
||||||
|
// Send the signed transaction using web3
|
||||||
|
web3.eth.sendSignedTransaction(rawTxHex) |
||||||
|
.on('receipt', receipt => { console.log('Receipt: ', receipt); }) |
||||||
|
.catch(error => { console.log('Error: ', error.message); }); |
||||||
|
console.log("******************************************"); |
||||||
|
console.log("Contract transaction sent, waiting for receipt."); |
||||||
|
console.log("******************************************"); |
||||||
|
}else{ |
||||||
|
console.log("******************************************"); |
||||||
|
console.log("You can for instance send this transaction manually with the following command:"); |
||||||
|
console.log("curl -X POST --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"" + rawTxHex + "\"],\"id\":1}'", provider); |
||||||
|
} |
||||||
|
})(); |
||||||
|
|
||||||
|
}) |
||||||
|
.catch(error => { console.log('Error: ', error.message); }); |
@ -0,0 +1,79 @@ |
|||||||
|
const Web3 = require('web3') |
||||||
|
const ethTx = require('ethereumjs-tx') |
||||||
|
const readline = require('readline'); |
||||||
|
|
||||||
|
async function askQuestion(query) { |
||||||
|
const rl = readline.createInterface({ |
||||||
|
input: process.stdin, |
||||||
|
output: process.stdout, |
||||||
|
}); |
||||||
|
|
||||||
|
return new Promise(resolve => rl.question(query, ans => { |
||||||
|
rl.close(); |
||||||
|
resolve(ans); |
||||||
|
})) |
||||||
|
} |
||||||
|
|
||||||
|
const args = process.argv.slice(2); |
||||||
|
|
||||||
|
// web3 initialization - must point to the HTTP JSON-RPC endpoint
|
||||||
|
var provider = args[0] || 'http://localhost:8545'; |
||||||
|
console.log("******************************************"); |
||||||
|
console.log("Using provider : " + provider); |
||||||
|
console.log("******************************************"); |
||||||
|
var web3 = new Web3(new Web3.providers.HttpProvider(provider)) |
||||||
|
web3.transactionConfirmationBlocks = 1; |
||||||
|
// Sender address and private key
|
||||||
|
// Second acccount in dev.json genesis file
|
||||||
|
// Exclude 0x at the beginning of the private key
|
||||||
|
const addressFrom = '0x627306090abaB3A6e1400e9345bC60c78a8BEf57' |
||||||
|
const privKey = Buffer.from('c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3', 'hex') |
||||||
|
|
||||||
|
// Receiver address and value to transfer
|
||||||
|
// Third account in dev.json genesis file
|
||||||
|
const addressTo = '0xf17f52151EbEF6C7334FAD080c5704D77216b732' |
||||||
|
const valueInEther = 2 |
||||||
|
|
||||||
|
// Get the address transaction count in order to specify the correct nonce
|
||||||
|
web3.eth.getTransactionCount(addressFrom, "pending").then((txnCount) => { |
||||||
|
// Create the transaction object
|
||||||
|
var txObject = { |
||||||
|
nonce: web3.utils.numberToHex(txnCount), |
||||||
|
gasPrice: web3.utils.numberToHex(1000), |
||||||
|
gasLimit: web3.utils.numberToHex(21000), |
||||||
|
to: addressTo, |
||||||
|
value: web3.utils.numberToHex(web3.utils.toWei(valueInEther.toString(), 'ether')) |
||||||
|
}; |
||||||
|
|
||||||
|
// Sign the transaction with the private key
|
||||||
|
var tx = new ethTx(txObject); |
||||||
|
tx.sign(privKey) |
||||||
|
|
||||||
|
//Convert to raw transaction string
|
||||||
|
var serializedTx = tx.serialize(); |
||||||
|
var rawTxHex = '0x' + serializedTx.toString('hex'); |
||||||
|
|
||||||
|
// log raw transaction data to the console so you can send it manually
|
||||||
|
console.log("Raw transaction data: " + rawTxHex); |
||||||
|
|
||||||
|
// but also ask you if you want to send this transaction directly using web3
|
||||||
|
(async() => { |
||||||
|
const ans = await askQuestion("******************************************\n\ |
||||||
|
Do you want to send the signed value transaction now ? (Y/N):"); |
||||||
|
if("y" == ans || "Y" == ans){ |
||||||
|
// Send the signed transaction using web3
|
||||||
|
web3.eth.sendSignedTransaction(rawTxHex) |
||||||
|
.on('receipt', receipt => { console.log('Receipt: ', receipt); }) |
||||||
|
.catch(error => { console.log('Error: ', error.message); }); |
||||||
|
console.log("******************************************"); |
||||||
|
console.log("Value transaction sent, waiting for receipt."); |
||||||
|
console.log("******************************************"); |
||||||
|
}else{ |
||||||
|
console.log("******************************************"); |
||||||
|
console.log("You can for instance send this transaction manually with the following command:"); |
||||||
|
console.log("curl -X POST --data '{\"jsonrpc\":\"2.0\",\"method\":\"eth_sendRawTransaction\",\"params\":[\"" + rawTxHex + "\"],\"id\":1}'", provider); |
||||||
|
} |
||||||
|
})(); |
||||||
|
|
||||||
|
}) |
||||||
|
.catch(error => { console.log('Error: ', error.message); }); |
@ -0,0 +1,14 @@ |
|||||||
|
{ |
||||||
|
"name": "createAndSendSignedTransaction", |
||||||
|
"version": "1.0.0", |
||||||
|
"description": "Script to generate a signed transaction data using JSON-RPC to check nonce and option to send it using web3", |
||||||
|
"scripts": { |
||||||
|
"test": "echo \"Error: no test specified\" && exit 1" |
||||||
|
}, |
||||||
|
"author": "Pegasys", |
||||||
|
"license": "Apache-2", |
||||||
|
"dependencies": { |
||||||
|
"ethereumjs-tx": "^1.3.7", |
||||||
|
"web3": "^1.0.0-beta.55" |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue