CRYPTO NEWS

web3.eth – getBlock FetchError: request to https://eth-mainnet.g.alchemy.io/v2/api_key failed, reason: getaddrinfo ENOTFOUND eth-mainnet.g.alchemy.io

I’m trying to get Eth blocks by blockNum using Alchemy’s apis.

The docs mention two methods: getBlockByHash and getBlockByNum, but those methods don’t exist on the web3.eth object. Here are the methods listed on the web3.eth object that contain ‘block’:

'transactionConfirmationBlocks',  'transactionBlockTimeout',  'blockHeaderTimeout',  'defaultBlock',  'getBlockNumber',  'getBlock',  'getBlockTransactionCount',  'getBlockUncleCount',  'getTransactionFromBlock' 

getBlock is shown in many code examples in the docs, including in the getBlockByNumber doc (https://docs.alchemy.com/alchemy/apis/ethereum/eth-getblockbynumber). But everywhere it is used in the docs just shows it called like const blockNumber = await web3.eth.getBlock('latest', true);

In that example it is only returning the blockNumber, which is something I already have. I’m trying to get metadata about a block using its blockNum, which the docs suggest is possible. I’ve called getBlock 4 different ways and they produce the following errors.

Method 1: getBlock(block_identifier=blockNum, full_transactions=True)

Error 1: FetchError: request to https://eth-mainnet.g.alchemy.io/v2/api_key failed, reason: getaddrinfo ENOTFOUND eth-mainnet.g.alchemy.io


Method 2: getBlockByHash({hash: "0xc0f4906fea23cf6f3cce98cb44e8e1449e455b28d684dfa9ff65426495584de6", boolean: "true"}) seen in docs (https://docs.alchemy.com/alchemy/apis/ethereum/eth-getblockbyhash)

Error 2: TypeError: web3.eth.getBlockByHash is not a function


Method 3: getBlock({ hash: hash, boolean: "true"})

Error 3: TypeError: web3.eth.getBlockByHash is not a function


Method 4: getBlock(hash)

Error 4: FetchError: request to https://eth-mainnet.g.alchemy.io/v2/api_key failed, reason: getaddrinfo ENOTFOUND eth-mainnet.g.alchemy.io


I’ve asked this question in a few places including Alchemys Discord. All I’m trying to is get transaction history (including block dates) from eth Contract addresses. I’d like to do this without having to run a full node locally, which is why Alchemy stuck out as a good option. I’ve tried BigQuery and the docs there are also super outdated.

Any suggestions of updated resources or how to run above function properly would be greatly appreciated.

abi.decode() and unused variables

I am decoding bytes as the following: // Decode Solidity tightly packed arguments (uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address)); // solhint-disable-line I get a compiler warning: Variable ‘_’ is declared but never used. What would be the right way to suppress this warning beautifully? I know how to do this::Listen

I am decoding bytes as the following:

      // Decode Solidity tightly packed arguments       (uint8 _, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address));  // solhint-disable-line 

I get a compiler warning:

Variable '_' is declared but never used. 

What would be the right way to suppress this warning beautifully? I know how to do this for function arguments, but not sure how what is a good practice with abi.decode.

The obvious way does not work:

/Users/moo/code/dawn-erc20/contracts/Staking.sol:255:23: ParserError: Expected ',' but got identifier       (uint8, uint128 stakeId, address behalf) = abi.decode(userData, (uint8, uint128, address));  // solhint-disable-line 

web3.eth – getBlock FetchError: request to https://eth-mainnet.g.alchemy.io/v2/api_key failed, reason: getaddrinfo ENOTFOUND eth-mainnet.g.alchemy.io

Shopping cart
There are no products in the cart!
Continue shopping
0