Last active
December 18, 2017 02:46
-
-
Save blueplanet/c2ba8f1a021a1e02eb8e7e70ec0f8032 to your computer and use it in GitHub Desktop.
イーサリアムのノードをAPIとして提供してくれるinfura.ioを使ってみる ref: https://qiita.com/blueplanet/items/4c58bed58f750c124fca
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ROPSTEN_MNEMONICとINFURA_ACCESS_TOKEN環境変数は事前時設定されている前提 | |
// HDはどの言葉の略語だろう。。。 | |
var HDWalletProvider = require("truffle-hdwallet-provider"); | |
var mnemonic = process.env.ROPSTEN_MNEMONIC; | |
var accessToken = process.env.INFURA_ACCESS_TOKEN; | |
module.exports = { | |
networks: { | |
ropsten: { | |
provider: function() { | |
return new HDWalletProvider( | |
mnemonic, | |
"https://ropsten.infura.io/" + accessToken | |
); | |
}, | |
network_id: 3, | |
gas: 500000 | |
} | |
} | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var Tx = require('ethereumjs-tx'); | |
var privateKey = new Buffer('e331b6d69882b4cb4ea581d88e0b604039a3de5967688d3dcffdd2270c0fd109', 'hex') | |
var rawTx = { | |
nonce: '0x00', | |
gasPrice: '0x09184e72a000', | |
gasLimit: '0x2710', | |
to: '0x0000000000000000000000000000000000000000', | |
value: '0x00', | |
data: '0x7f7465737432000000000000000000000000000000000000000000000000000000600057' | |
} | |
var tx = new Tx(rawTx); | |
tx.sign(privateKey); | |
var serializedTx = tx.serialize(); | |
//console.log(serializedTx.toString('hex')); | |
//f889808609184e72a00082271094000000000000000000000000000000000000000080a47f74657374320000000000000000000000000000000000000000000000000000006000571ca08a8bbf888cfa37bbf0bb965423625641fc956967b81d12e23709cead01446075a01ce999b56a8a88504be365442ea61239198e23d1fce7d00fcfc5cd3b44b7215f | |
web3.eth.sendRawTransaction('0x' + serializedTx.toString('hex'), function(err, hash) { | |
if (!err) | |
console.log(hash); // "0x7f9fade1c0d57a7af66ab4ead79fade1c0d57a7af66ab4ead7c2c2eb7b11a91385" | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment