1.ropsten での送金テスト code
2.code
"use strict"; const Web3 = require('web3') const web3 = new Web3('https://ropsten.infura.io/v3/xxxxxxxxxxxxxxxxxxxxxxxxx') const { eth } = web3; const Tx = require('ethereumjs-tx').Transaction; (async() => { const sellerAddr = 'seller adder' const buyerAddr = 'buyer adder' const sellerPrivateKey = 'seller privatekey' const buyerPrivateKey = 'buyer privatekey' const count = await eth.getTransactionCount(buyerAddr); console.log("count="+count); const nonce = ""+web3.utils.toHex(count); const gasPrice = await eth.getGasPrice() console.log("gasPrice"+gasPrice) const sellerBalanceStart = await eth.getBalance(sellerAddr); const buyerBalanceStart = await eth.getBalance(buyerAddr); console.log("Before Balance"); console.log("seller = "+sellerBalanceStart); console.log("buyer = "+buyerBalanceStart); const transactionObj = { nonce : nonce, chainId : 3, gasPrice: web3.utils.toHex(gasPrice), gasLimit: '0x27100', to: sellerAddr, value: web3.utils.toHex(1*1000000000), timeout : web3.utils.toHex(5000) } const privateKeyBUF = Buffer.from(buyerPrivateKey, 'hex'); const tx = new Tx ( transactionObj , { chain: 'ropsten' }); tx.sign(privateKeyBUF); const serializedTx = tx.serialize(); const serializedTx_hex = '0x' + serializedTx.toString('hex'); const transaction = await eth.sendSignedTransaction(serializedTx_hex); console.log(transaction); const sellerBalanceEnd = await eth.getBalance(sellerAddr); const buyerBalanceEnd = await eth.getBalance(buyerAddr); console.log("After Balance"); console.log("seller = "+sellerBalanceEnd); console.log("buyer = "+buyerBalanceEnd); //await eth.getPendingTransactions().then(console.log); var subscription = web3.eth.subscribe('pendingTransactions', function(error, result){ if (!error) console.log(result); }) .on("data", function(transaction){ console.log(transaction); }); })();