Closed3
EIP-1559 なトランザクションを投げてみる
ロンドンハードフォークによって、EIP-1559 がメインネットに来たので試してみる
EIP-1559: Fee market change for ETH 1.0 chain
リポジトリ
以下 Ethers.js の場合
サポートされたバージョン
v5.4.0 から EIP-1559 がサポートされた
トランザクションの投げ方
sendTransaction
に type
というオプションを渡せて、これによってレガシーか EIP-1559 かを設定できる
デフォルトでは EIP-1559 なトランザクションとして、トランザクションが投げられる
async function sendLegacyTx(wallet: Wallet) {
return wallet.sendTransaction({
to: wallet.address,
type: 0,
});
}
async function sendEIP1559Tx(wallet: Wallet) {
return wallet.sendTransaction({
to: wallet.address,
// type が undefined だと 2 (EIP-1559) としてトランザクションが作成される
// type: 2,
});
}
実際に投げたトランザクション
Web3.js の場合
サポートされたバージョン
v1.5.1 でサポートされた
トランザクションの投げ方
sendTransaction
に type
というパラメータが渡せて 0x2
を渡すと EIP-1559 なトランザクションになる。デフォルトでは Legacy なトランザクションが投げられる
async function sendLegacyTx(web3: Web3, account: Account) {
const from = account.address;
const to = account.address;
const tx = await web3.eth.sendTransaction({
from,
to,
gas: "21000",
});
return tx;
}
async function sendEIP1559Tx(web3: Web3, account: Account) {
const from = account.address;
const to = account.address;
// sendTransaction の型定義が EIP-1559 に対応していないので as any 必須
const tx = await web3.eth.sendTransaction({
from,
to,
type: "0x2",
gas: "21000",
} as any);
return tx;
}
実際に投げたトランザクション
Legacy https://rinkeby.etherscan.io/tx/0xde0217561dae071f8b62023c08ebca7d6ccbfc0b38bd4c4cd18eb05cb1460ea3
EIP-1559 https://rinkeby.etherscan.io/tx/0xfcaa150282ee1fc5449a1d51c44042d5020d5a82dcc2b26c2cbdce6439749871
このスクラップは2022/08/06にクローズされました