every sec send transaction nonce++
https://medium.com/finnovate-io/how-do-i-sign-transactions-with-web3-f90a853904a2
https://ethereum.stackexchange.com/questions/60611/defining-the-transaction-object-for-offline-transaction-signing-using-web3-js-f
https://github.com/ethereum/web3.js/issues/1430
https://programtheblockchain.com/posts/
signTransaction(tx, “0x”+privateKey) “0x” privatekey need becarful.
--ws --wsaddr 0.0.0.0 --wsorigins "*" --wsapi "db,admin,debug,miner,eth,net,web3,network,txpool" var fs = require('fs'); var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://192.168.99.100:18545"); var wsprovider = new Web3.providers.WebsocketProvider("ws://192.168.99.100:18546"); //var web3 = new Web3(provider); var web3 = new Web3(wsprovider); console.log("before web set account: %o", web3.eth.defaultAccount); const privateKey = '138cbbfb21686ddc3b5ffeb2cfc83491175af68319977acb81d0ae93392c626c'; const account = web3.eth.accounts.privateKeyToAccount('0x' + privateKey); //web3.eth.accounts.wallet.add(account); //console.log("private key import to account: %o", account.
Important!! web3.eth.sendTransaction({ data: bytecode “certjson.bytecode” or “certjson.bytecode.object” MUST Have “0x” at line First Character Use Truffle 1. run https://www.trufflesuite.com/docs/truffle/quickstart
1-1. run command
mkdir testtruffle cd testtruffle npm i web3 truffle unbox metacoin truffle test ./test/TestMetaCoin.sol truffle test ./test/metacoin.js truffle compile 2. modify truffle-config.js
Here use your private poa chain networkinfo. from address must be can used. genesis file can put this address.
module.exports = { // Uncommenting the defaults below // provides for an easier quick-start with Ganache.
Use https://remix.ethereum.org Get Contract json and data. In remix website, Compile finish. See Compliation Details. 1. ABI: click ABI buttion, get data. Use http://jsonviewer.stack.hu/ remove space 2. Compliation Details -> WEB3DEPLOY -> get data 3. cContract.options.from need put correct.
var Web3 = require("web3"); var provider = new Web3.providers.HttpProvider("http://ganache:8545"); var web3 = new Web3(provider); //abi var cContract = new web3.eth.Contract([{"constant":false,"inputs":[{"name":"x","type":"uint256"}],"name":"set","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"get","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"}]) //bytecode cContract.options.data = '0x608060405234801561001057600080fd5b5060bf8061001f6000396000f30060806040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166360fe47b18114604d5780636d4ce63c146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b506076608d565b60408051918252519081900360200190f35b600055565b600054905600a165627a7a72305820765480c908e5e28e3233e18bfa422944b42cad5fc08b77d7b22d3ddd7016a1380029' cContract.options.from = '0xoooxxxoooxxxoooxxxoooxxxoooxxx' cContract.options.gas = '4700000' console.
HDWalletProvider engine.stop() p = HDWalletProvider(MNEMONIC_SYSTEM, "http://ganache:8545", 0); p.engine.stop(); HDWalletProvider engine.stop() and pool export function GetHdProvider(id: number, rpcurl: string) { //return new HDWalletProvider(MNEMONIC_SYSTEM, url, id); return id==0?Provider1Pool.acquire():Provider2Pool.acquire(); } // Normal use const hdProvider0 = await GetHdProvider(0, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); const hdProvider1 = await GetHdProvider(1, providerUrl).then(function(client) {return client}).catch(function(err) {throw new HttpException(err.toString(), HttpStatus.BAD_REQUEST);}); // Normal release ReleaseHDProvider1(hdProvider1 ); // Pool code const genericPool = require("generic-pool"); const opts = { max: 10, // maximum size of the pool min: 2, // minimum size of the pool idleTimeoutMillis: 30000, log: true }; const factory0 = { // maybe different parms create: function() { return new HDWalletProvider(MNEMONIC_SYSTEM, RPCURL, 0); }, destroy: function(client) { client.
https://github.com/adrianmcli/web3-vs-ethers