# Gas取得 ###### tags: `EVM` ## EIP-1559 標準 ETH1.0チェーンの手数料市場の変化に対応した規格 イーサリアムタイプ1またはタイプ2トランザクションに対応 https://eips.ethereum.org/EIPS/eip-1559 [**2022年1月17日からPolygonがEIP-1559に対応**](https://blog.polygon.technology/eip-1559-upgrades-are-going-live-on-polygon-mainnet/) ### イーサリアムの手数料市場メカニズム ![](https://i.imgur.com/mb5FQ65.png) **EIP-1559はガス価格のいくらかの低下につながる場合があります。** - ブロックが50%を超えていっぱいになると、基本料金が最大12.5%増減 - ブロックが100%いっぱいの場合、基本料金は12.5%増加 - 50%が満杯の場合、基本料金は同じ - それが0%いっぱいの場合、基本料金は12.5%減少 (ネットワークの混雑が激しい期間中、基本料金は、需要が減少するまで、ブロックあたりの理想気体制限を超える需要量に応じて12.5%調整されます。) ### use web3 js ```javascript= const web3 = new Web3.providers.HttpProvider("json-rpc"); let web3Provider = new ethers.providers.Web3Provider(web3) async function getGasPrice() { return await web3Provider.getFeeData().then(async function (res) { let maxFeePerGas = res.maxFeePerGas; let maxPriorityFeePerGas = res.maxPriorityFeePerGas; return { maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, }; }); } ``` ### use ethers js ```javascript= const web3Provider = new ethers.providers.InfuraProvider( "kovan", "INFURA_ID" ); async function getGasPrice() { return await web3Provider.getFeeData().then(async function (res) { let maxFeePerGas = res.maxFeePerGas; let maxPriorityFeePerGas = res.maxPriorityFeePerGas; return { maxFeePerGas: maxFeePerGas, maxPriorityFeePerGas: maxPriorityFeePerGas, }; }); } ``` ※ウォレットは、トランザクションがユーザーにとってどれほど緊急であるかに基づいて、事前定義された設定を提供します。MetaMaskを使用すると、ユーザーは、前のブロックの推定使用量とトランザクションのタイプに基づいて、トランザクションの優先度を「低」、「中」、「高」に設定するオプションを引き続き利用できます。