LoginSignup
0
0

More than 1 year has passed since last update.

Ganache-cliでEIP1559 Type 2 トランザクションを試す

Posted at

はじめに

現時点(2021/12/21)のganache-cliのstable versionでは、Type2のトランザクション(EIP-1559)がサポートされていないようです1

現時点ではベータ版のv7でType2のトランザクションがサポートされているようです。

本記事では、ganache-cliのv7ベータ版において、EIP-1559の特徴の1つであるmax_priority_fee_per_gasmax_fee_per_gasが、MetaMask、Web3(javascript)で指定できることを確認します。

インストール&起動

インストール

npm install ganache@beta

私の場合、ganache-cliはプロジェクト内にインストールしたいため上記のようにしました。

参考

起動

npx ganache-cli -d -p 7545

ログ(一部省略しています)

ganache v7.0.0-beta.1 (@ganache/cli: 0.1.1-beta.1, @ganache/core: 0.1.1-beta.1)
Starting RPC server

Available Accounts
==================
(0) 0x90 ..... (1000 ETH)
(1) 0xFF ..... (1000 ETH)
(2) 0x22 ..... (1000 ETH)
(3) 0xE1 ..... (1000 ETH)
(4) 0xd0 ..... (1000 ETH)
(5) .... 
(6) ....
(7) ....
(8) ....
(9) ....

Private Keys
==================
(0) 0x4 ....
(1) 0x6 ....
(2) .... 
(3) ....
(4) ....
(5) ....
(6) ....
(7) ....
(8) ....
(9) ....

HD Wallet
==================
Mnemonic:      myth .....
Base HD Path:  m/44'/60'/0'/0/{account_index}

Default Gas Price
==================
2000000000

BlockGas Limit
==================
12000000

Call Gas Limit
==================
9007199254740991

Chain Id
==================
1337

RPC Listening on 127.0.0.1:7545

引数について補足

  • -d--deterministicの省略形で、起動毎にテスト用アドレスを変えたくないため、指定しています。
  • -p--portの省略形で、JSPN-RPCのリクエストなどを受け付けるポート番号を指定します。デフォルトとは異なるポートを使用したかったため、指定しています。

参考

試す

MetaMaskで送金

MetaMaskにNetworksの設定および、起動時のログをもとにアカウント×2を追加したのちETH
の送金を行います。この時max_priority_fee_per_gasmax_fee_per_gasが指定できることを確認します。

「send」
metamask_1_b.png

適当に送金するETHの額を入力し、「Next」
metamask_2_b.png

「Estimated gas fee」の部分の「EDIT」をクリック
metamask_3_b.png

「Advanced Options」をクリック
metamask_4_b.png

「Max priority free」と「Max fee」が指定できます。このまま「Save」、「Confirm」すれば送金のトランザクションが発行されます。
metamask_5_b.png

metamask_6_b.png

Web3(javascript)で送金

やっていることは上記のMetaMaskの例と同じですが、一応web3.jsのAPIでも試してみます。

簡易的なWebアプリケーションを作って試します。

トランザクションを発行している部分のソースコードは以下です(→全ソースコード)。


    const ethToSendInWei = web3.utils.toWei(eth, 'ether');
    const maxFeePerGasInWei = web3.utils.toWei(maxFeePerGas, "gwei");
    const maxPriorityFeePerGasInWei = web3.utils.toWei(maxPriorityFeePerGas, "gwei");

    const receipt = await web3.eth.sendTransaction({
      from: accounts[0], 
      to: toAddress,
      value: ethToSendInWei,
      type: "0x2",
      gas, 
      maxFeePerGas: maxFeePerGasInWei, 
      maxPriorityFeePerGas: maxPriorityFeePerGasInWei
    });

参考

MetaMask上のアカウントとサイトが接続された状態で「send」
web3app_1_b.png

「Estimated gas fee」の部分の「EDIT」をクリック
web3app_2_b.png

「Edit suggested gas fee」をクリック
web3app_3_b.png

「Max priority free」と「Max fee」が指定できます。ここには、Webアプリケーション(javascript)で指定したmaxPriorityFeePerGasmaxFeePerGasの値が表示されています。このまま「Save」、「Confirm」すれば送金のトランザクションが発行されます。
web3app_4_b.png

web3app_5_b.png

その他参考


  1. 例えば、Web3+MetaMaskで、トランザクションを発行しようとした際にInvalid transaction params: params specify an EIP-1559 transaction but the current network does not support EIP-1559のようなエラーに遭遇します。 

0
0
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
0
0