{"id":2379,"date":"2022-05-13T14:39:11","date_gmt":"2022-05-13T05:39:11","guid":{"rendered":"https:\/\/blog.wsd.sh\/?p=2379"},"modified":"2022-05-18T15:30:45","modified_gmt":"2022-05-18T06:30:45","slug":"web3-signedtransactiondata%e3%81%aenonce%e5%80%a4","status":"publish","type":"post","link":"https:\/\/blog.wsd.sh\/?p=2379","title":{"rendered":"<small>ganache : web3 signedTransactionData \u306e nonce \u5024<\/small>"},"content":{"rendered":"<p>\uff11\uff0e\u74b0\u5883\u3068method<br \/>\n\u30fbweb3@1.7.3<br \/>\n\u30fbganache@7.1.0<br \/>\n\u30fbweb3.eth.sendSignedTransaction(signedTransactionData [, callback])<\/p>\n<p>\uff12\uff0eParameter \u306e signedTransactionData<br \/>\n\u30fbSigned transaction data in HEX format<br \/>\n\u30fbtransactionObject \u306f\u4e0b\u3067\u51fa\u3066\u304f\u308b<br \/>\n\u30fbprivateKeyBUF\u306fprivateKey \u3092 hex \u306b\u3057\u305f\u3082\u306e<\/p>\n<pre>\r\n    var  tx = new Tx ( transactionObject );\r\n\r\n    tx.sign(privateKeyBUF);\r\n\r\n    const serializedTx = tx.serialize();\r\n<\/pre>\n<p>\uff13\uff0eExample\u3067\u306e transactionObject \u306e nonce\u5024<br \/>\n\u30fb\u9d5c\u5451\u307f\u306b\u3057\u3066\u306f\u3044\u3051\u306a\u3044\u7b87\u6240<br \/>\nExample\u3067\u3001nonce: &#8216;0x00&#8217;\u3068\u306a\u3063\u3066\u3044\u308b\u304c\u3001Transaction\u306e\u5b9f\u884c\u6570\u3067\u5897\u3048\u3066\u3044\u304f\u3002<br \/>\n\u5f93\u3063\u3066\u3001\u3059\u3067\u306bTransaction\u3092\u5b9f\u884c\u3057\u305f\u5f8c\u3060\u3068\u3001nonce: &#8216;0x00&#8217;\u306etansaction\u306f\u5931\u6557\u3059\u308b\u3002<\/p>\n<pre>\r\nExample\r\n\r\nvar Tx = require('ethereumjs-tx').Transaction;\r\nvar privateKey = Buffer.from('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex');\r\n\r\nvar rawTx = {\r\n  nonce: '0x00',\r\n  gasPrice: '0x09184e72a000',\r\n  gasLimit: '0x2710',\r\n  to: '0x0000000000000000000000000000000000000000',\r\n  value: '0x00',\r\n  data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057'\r\n}\r\n<\/pre>\n<p>\uff14\uff0etransactionObject \u306e nonce\u5024\u306e\u6c42\u3081\u65b9<br \/>\n\u30fbganache \u306e nonce \u306f\u3001contract address\uff08account\uff09\u3067\u5b9f\u884c\u3057\u305ftransaction\u306e\u6570\u3092\u6307\u5b9a<br \/>\n\u30fbnonce \u306f0 \u304b\u3089\u59cb\u307e\u308b\u306e\u3067\u3001nonce\u306fgetTransactionCount\u3067\u6c42\u3081\u305f\u5024\u306b\u306a\u308b<br \/>\n\u30fb\u6b21\u306b\u3001getTransactionCount \u3067\u6c42\u3081\u305f\u5024\u3092 hex \u306b\u3057\u3066 transactionObject \u306b\u8a2d\u5b9a\u3059\u308b<\/p>\n<pre>\r\n    const count = web3.eth.getTransactionCount(web3, contract_address);\r\n    const transactionObject = {\r\n            nonce   : web3.utils.toHex( count ),\r\n            gasPrice: '0x09184e72a000',\r\n            gasLimit: web3.utils.toHex(gasLimit),\r\n            to      : to_account,\r\n            value   : makePaymantTo,\r\n            data    : ipfs_cid_hex\r\n        }\r\n\r\n<\/pre>\n<p>\uff15\uff0eganache \u3067\u3001sendSignedTransaction\u3092\u5b9f\u884c\u3057\u305f\u5f8c\u306eresult\u3067\u306etype \u306e\u5024<\/p>\n<pre>\r\ntype : \u201d0x0\u201d\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\uff11\uff0e\u74b0\u5883\u3068method \u30fbweb3@1.7.3 \u30fbganache@7.1.0 \u30fbweb3.eth.sendSignedTransaction(signedTransactionData [, callback]) \uff12\uff0eP&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/2379"}],"collection":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2379"}],"version-history":[{"count":15,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/2379\/revisions"}],"predecessor-version":[{"id":2381,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=\/wp\/v2\/posts\/2379\/revisions\/2381"}],"wp:attachment":[{"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2379"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2379"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.wsd.sh\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2379"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}