4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【ethereumjs-tx】署名付きトランザクションデータ作成【Ethereum】

Last updated at Posted at 2017-12-12

ブラウザベースのethereumjs-txを使うメモ

ethereumjs-tx読み込み

<script src="ethereumjs-tx-1.3.3.min.js" type="text/javascript"></script>

ブラウザベースではグローバル変数 ethereumjs を使う(EthJSでなく)

ex.

function createRawTxData(nonce,gasPrice,gasLimit,to,value,data,privateKey) {
  
    var rawTx = {};
    
    rawTx['nonce'] = nonce;
    rawTx['gasPrice'] = gasPrice;
    rawTx['gasLimit'] = gasLimit;
    rawTx['to'] = to;
    rawTx['value'] = value;
    rawTx['data'] = data;
    
    var tx = new ethereumjs.Tx(rawTx);

    // Buffer.Buffer はタイポでないです
    var pk = new ethereumjs.Buffer.Buffer(privateKey, 'hex');

    tx.sign(pk);
    
    return tx.serialize().toString('hex');

    // output
    // 0xf86180820834820a9694a813cb047ffd55848bed64bf8cbaa325b4ea620780802ba025d4323cb9564aab68be0ca3b26b195c26d5b0a0bd0a5c774786e2684e242840a03b0ed69cf748bc7f3e3aacda668fbf7eef6c1f662eb71fc61fe7ab70b76c817d
}

github: ethereumjs-tx(browser-builds)
cf(Stack Over Flow). how to use ethereumjs-tx.js in a browser

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?