0

I tried This Code With The GetPastEvents to get Transactions from a smart contract. but the console return 0 . and the error is Null.

Check the code below . Help me fix this please!!

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


const abi = [ABI_CODE_FROM_SMARTCONTRACT]
const address = '0x95dAaaB98046846bF4B2853e23cba236fa394A31'

const contract = new web3.eth.Contract(abi, address)


contract.getPastEvents('allEvents', {fromBlock: 9851116, toBlock:'latest'}, (err, events) => {
    console.log(events.length)
})
3
  • It is not possible to help you, as your question does not have context. What events, which Ehereum network, and so on. I suggest you edit your question and add more background, context and detail. Commented Apr 18, 2020 at 14:50
  • okey Check it now. I follow a tutorial i did the same. i change the AllEvents To allEvents, this code must show a number of transactions from the block to latest.!
    – midoharbi
    Commented Apr 18, 2020 at 14:58
  • What smart contract is it? Can share the link and then check on EtherScan that the smart contract has any events or transactions? Commented Apr 18, 2020 at 15:09

1 Answer 1

0

You're connecting to ropsten:

const web3 = new Web3('https://ropsten.infura.io/v3/......')

There is no contract at ropsten address 0x95dAaaB98046846bF4B2853e23cba236fa394A31.

But there is one at mainnet address 0x95dAaaB98046846bF4B2853e23cba236fa394A31.

So what you really want is probably to connect to mainnet instead:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.