Last active
December 7, 2016 13:38
-
-
Save noeleon930/82507bd8acb827706e65040cf0b17d95 to your computer and use it in GitHub Desktop.
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
| 'use strict' | |
| const Web3 = require('web3') | |
| const keythereum = require('keythereum') | |
| const Tx = require('ethereumjs-tx') | |
| let web3 = new Web3(new Web3.providers.HttpProvider('http://140.119.164.155:8545')); | |
| // read from key file | |
| let keyObj = { | |
| "address": "帳戶位址", | |
| "crypto": { | |
| "cipher": "aes-128-ctr", | |
| "ciphertext": "a48f507dc90814595885714c322a5e0f884b1f617afba30011bbc4fa09bda201", | |
| "cipherparams": { | |
| "iv": "69b17ebb299538d067f13574e6cbbff9" | |
| }, | |
| "kdf": "scrypt", | |
| "kdfparams": { | |
| "dklen": 32, | |
| "n": 262144, | |
| "p": 1, | |
| "r": 8, | |
| "salt": "f96e9de579e88cfd0de0f5159cf298d5b9e352f7084294c21538c5e6b52af8cd" | |
| }, | |
| "mac": "4de297f565db86a72e10edff4f431905902bb42d805c1a84dcad4a9fe2d47ca9" | |
| }, | |
| "id": "85b38172-5844-44f2-949a-d6f72b368e2d", | |
| "version": 3 | |
| } | |
| let privateKey = keythereum.recover('密碼', keyObj) | |
| console.log(privateKey) | |
| let tx = new Tx() | |
| // nonce 每個帳戶不同 | |
| // 請參照 https://github.com/ethereum/wiki/wiki/JavaScript-API#web3ethgettransaction | |
| tx.nonce = 1680 | |
| tx.gasPrice = 100 | |
| tx.gasLimit = 460000 | |
| tx.to = '0x9d212e595580f7f4dd3b5e13cd38c94d7a290785' | |
| tx.value = 10 | |
| tx.sign(privateKey) | |
| let serializedTx = tx.serialize() | |
| console.log(serializedTx) | |
| web3.eth.sendRawTransaction(serializedTx.toString('hex'), function (err, hash) { | |
| if (!err) | |
| console.log(hash); | |
| else | |
| console.log(err) | |
| }); | |
| console.log(web3.eth.accounts) | |
| console.log(serializedTx.toString('hex')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment