Skip to content

EIP-1559

The London hard fork introduced a new EIP that modifies how gas estimation and costs work for transactions on Polygon.

Due to this, there is a change in how the transaction object is formed when sending transactions on Polygon. A new transaction type called Type 2 Transaction has been introduced. The legacy type transactions will still be compatible but it is recommended to shift to the new style. You can navigate to the end of this document to directly peek into the code.

How legacy transactions (Type 0) work

When you submit a transaction, you also send a gasPrice which is an amount you are offering to pay per gas consumed. Then, when you submit the transaction, miners can decide to include your transaction or not based on your gasPrice bid. Miners will prioritize the highest gas prices.

Sending Type 2 transactions with EIP1559

It is a similar concept, the gasPrice will be split into a baseFee and a priorityFee.

Every transaction needs to pay the base fee, which is calculated based on how full the previous block was. Transactions can also offer the miner a priorityFee to incentivize the miner to include the transaction in the block.

Sending legacy transactions

Only the gasPrice needed to be mentioned in the legacy transaction prior to the London fork.

The following code example shows sending transaction using a type 0 transaction:

const sendLegacyTransaction = async () => {
    const web3 = new Web3('https://polygon-rpc.com');

    await web3.eth.sendTransactions({
        from: 0x05158d7a59FA8AC5007B3C8BabAa216568Fd32B3,
        to: 0xD7Fbe63Db5201f71482Fa47ecC4Be5e5B125eF07,
        value: 1000000000000000000,
        gasPrice: 200000000000
    })
}

Sending EIP1559 transactions

Add maxPriorityFeePerGas field

The closest analogy to the gas:gasPrice combination is gas:maxPriorityFeePerGas. Since the baseFee needs to be paid regardless, we can just submit a bid on the tip for the miner. Note that the Polygon Gas Station V2 can be used to get the gas fee estimates.

The following code example shows sending transaction in Type 2 method:

// Example for
const sendEIP1559Transaction = async () => {
    const web3 = new Web3('https://polygon-rpc.com');

    await web3.eth.sendTransactions({
        from: 0xFd71Dc9721d9ddCF0480A582927c3dCd42f3064C,
        to: 0x8C400f640447A5Fc61BFf7FdcE00eCf20b85CcAd,
        value: 1000000000000000000,
        maxPriorityFeePerGas: 40000000000
    })
}

The Polygon Gas Station V2 can be used to get the gas fee estimates.

Polygon Gas Station V2 Endpoint:

https://gasstation.polygon.technology/v2

Polygon Gas Station V2 sample response:

{
 "safeLow": {
  "maxPriorityFee": 37.181444553750005,
  "maxFee": 326.2556979087
 },
 "standard": {
  "maxPriorityFee": 49.575259405,
  "maxFee": 435.00759721159994
 },
 "fast": {
  "maxPriorityFee": 61.96907425625,
  "maxFee": 543.7594965144999
 },
 "estimatedBaseFee": 275.308812719,
 "blockTime": 6,
 "blockNumber": 23948420
}

See also

Please read the following articles to get a better understanding of sending EIP-1559 transactions: