Why computed number of confirmations is a lot larger than value from the block explorer

confirmationspolygonweb3.py

As it has been explained here, here and even here I proceed with computing number of confirmations for a given txid. It works but gives weird results which are not consistent with the block explorer.

Using

receipt = w3.eth.get_transaction_receipt(txid)
result = _contract.events.Transfer().processReceipt(receipt, errors=DISCARD)

I obtain

AttributeDict({
    {
        'from': '0x0000000000000000000000000000000000000000',
        'to': '******************************************',
        'tokenId': ***
    },
    'event': 'Transfer',
    'logIndex': ***,
    'transactionIndex': **,
    'transactionHash': HexBytes('******************************************************************'),
    'address': '******************************************',
    'blockHash':    HexBytes('******************************************************************'),
    'blockNumber': 23504211
}

(I starred sensitive values) then using

print(w3.eth.block_number)

I get

23542487

So following the current_block_number - tx_block_number we find this tx has 23542487 - 23504211 = 38276 confrimations which seems like a crazy large number. Just to compare, at the same time https://polygonscan.com/ indicates 346 confirmations.

screenshot of the polygon scan block explorer showing smaller number of confirmations

I find this super confusing. Anyone could clarify how number of confirmations is computed on the Polygon Network?

EDIT:

Is it possible that w3.eth.block_number gives me the current ETH block number and not Polygon block number even if I connected to Polygon RPC node?

Best Answer

Ok, that is a bit embarrasing, but it turns out I had a bug that was comparing wrong transaction hash, instead of previous one it was taking previous-previous one. Everything works fine, those numbers match, keep using Polygon!

Related Topic