mohamed gamal
mohamed gamal

Reputation: 26

getting gassless transactions contract address

i'm getting transactions by block from covalent with nodejs, but some transactions doesn't have a gass fees sections which means i can't get contract address for those, how can i get contract for those gassless transactions. i'm getting transactions by calling this api https://api.covalenthq.com/v1/{chain-name}/address/{walletAddress}/transactions_v3/ with chain and wallet address. see docs https://www.covalenthq.com/docs/api/transactions/get-recent-transactions-for-address-v3/ i have tried to access transaction.gas_metadata.contract_address but some transactions don't have gas_metadata but i really need this data about each transaction, also for covalent it's a multi currency platform so i don't have to worry about each chain individually.

i searched and found that i can get this data from the sender address but don't know how or where this data will be available for this transactions because it's really critical part and i don't wanna try things like this on production, so it will be great if anyone else faced this issue.

how to get those gassless transaction contract address

Upvotes: 0

Views: 46

Answers (1)

dincer.unal
dincer.unal

Reputation: 173

Use can use an Ethereum Archive Node If the Covalent API doesn't provide the contract address, you can query an Ethereum archive node (like Infura) directly using the transaction hash to retrieve more details about the transaction, including the contract address

const Web3 = require('web3');
const web3 = new Web3('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID');

const transactionHash = 'YOUR_TRANSACTION_HASH';

web3.eth.getTransaction(transactionHash, (error, transaction) => {
  if (error) {
    console.error(error);
  } else {
    console.log('Contract Address:', transaction.to);
  }
});

You can fetch additional details, including the contract address, from Etherscan's API.

Example API endpoint https://api.etherscan.io/api?module=transaction&action=gettxinfo&txhash=YOUR_TRANSACTION_HASH&apikey=YOUR_ETHERSCAN_API_KEY

If you frequently need to query contract addresses for gasless transactions, you can consider maintaining a local database that stores this information. You can periodically fetch transaction data from Covalent, check if the contract address is missing, and then retrieve the contract address from another source (e.g., Ethereum archive node or Etherscan) and store it in your database

Upvotes: 0

Related Questions