1.環境とmethod
・web3@1.7.3
・ganache@7.1.0
・web3.eth.sendSignedTransaction(signedTransactionData [, callback])
2.Parameter の signedTransactionData
・Signed transaction data in HEX format
・transactionObject は下で出てくる
・privateKeyBUFはprivateKey を hex にしたもの
var tx = new Tx ( transactionObject );
tx.sign(privateKeyBUF);
const serializedTx = tx.serialize();
3.Exampleでの transactionObject の nonce値
・鵜呑みにしてはいけない箇所
Exampleで、nonce: ‘0x00’となっているが、Transactionの実行数で増えていく。
従って、すでにTransactionを実行した後だと、nonce: ‘0x00’のtansactionは失敗する。
Example
var Tx = require('ethereumjs-tx').Transaction;
var privateKey = Buffer.from('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex');
var rawTx = {
nonce: '0x00',
gasPrice: '0x09184e72a000',
gasLimit: '0x2710',
to: '0x0000000000000000000000000000000000000000',
value: '0x00',
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'
}
4.transactionObject の nonce値の求め方
・ganache の nonce は、contract address(account)で実行したtransactionの数を指定
・nonce は0 から始まるので、nonceはgetTransactionCountで求めた値になる
・次に、getTransactionCount で求めた値を hex にして transactionObject に設定する
const count = web3.eth.getTransactionCount(web3, contract_address);
const transactionObject = {
nonce : web3.utils.toHex( count ),
gasPrice: '0x09184e72a000',
gasLimit: web3.utils.toHex(gasLimit),
to : to_account,
value : makePaymantTo,
data : ipfs_cid_hex
}
5.ganache で、sendSignedTransactionを実行した後のresultでのtype の値
type : ”0x0”