i test web3js by geth,i build private net in local.i try to call getPastlog ,but return empty array.

const Web3 = require("web3");
// const web3 = new Web3(new Web3.providers.HttpProvider("https://rinkeby.infura.io/v3/770daaf97ee14e0aa77ac105bbcdd79f"));
const web3 = new Web3(new Web3.providers.HttpProvider(""));

    topics: ['0xdd970dd9b5bfe707922155b058a407655cb18288b807e2216442bca8ad83d6b5'] //topics:[web3.utils.sha3("adduintevent(uint256,uint256)")]

address and topics is right ,because i get them by getPastEvents

contract.getPastEvents('Log', {
    // filter: {myIndexedParam: [20,23], myOtherIndexedParam: '0x123456789...'}, // Using an array means OR: e.g. 20 or 23
    fromBlock: 0,
    toBlock: 'latest'
}, function (error, events) {

===========result ==========
  data: '0x00000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000a54686520576f726c642100000000000000000000000000000000000000000000',
  topics: [

so, i want to konw why i can't get anything by pastlog.Who can help me...

1 Answer 1


Try to use this syntax:

const Web3 = require('web3');
const web3 = new Web3(node_URL);

  (err, logs) => {

And it will return this (only a short sample as it's super long):

    data: '0x',
    blockNumber: 15148918,
    transactionHash: '0x1dc6e2b1b205100f355c9ed23a5692d35814953371f3117c722d2e685434a210',
    transactionIndex: 41,
    blockHash: '0x9740cc9644b12da740fb4bcee5cc7eab47a14a67cac90047bdd38f606af77791',
    logIndex: 95,
    removed: false,
    id: 'log_83c8653c'
    address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
    topics: [
    data: '0x000000000000000000000000000000000000000000000000000000000ea3d300',
    blockNumber: 15148918,
    transactionHash: '0x845dd44a580847c657e20d1575b4329961b1b53d03aafa6e50fa993bc51f3a2d',
    transactionIndex: 42,
    blockHash: '0x9740cc9644b12da740fb4bcee5cc7eab47a14a67cac90047bdd38f606af77791',
    logIndex: 96,
    removed: false,
    id: 'log_dcfe5163'

You can get more details about this RPC method in the Chainstack docs!

You can use the Node API reference page in the Chainstack docs to find examples of the JSON RPC methods in web3.js, web3.py, eth.rb, and cURL!

  • thanks ,but it still return empty array .I can get data form test net ,such as rinkeby,but in my local geth will return empty array . I don't know if my start command lost smoething.
    – 张三次
    Jul 17, 2022 at 2:03
  • This is my start command: geth --http --http.corsdomain '' --networkid 201 --mine --miner.threads 2 --syncmode full --datadir data --http --ws --ws.port "8546" --port "30303" --http.corsdomain "" --nat "any" --http.api eth,web3,personal,net --allow-insecure-unlock --unlock 0,1 --password ./password.sec
    – 张三次
    Jul 17, 2022 at 2:04
  • Could it be the network ID? It should be 1 for mainnet. Once you make it work, you'll need to use the syntax I sent because you will always get an empty array with the original one. Jul 20, 2022 at 20:50
  • thanks,i has resolved question. i need give blocknum as param for from and to ,so that i can get data.
    – 张三次
    Jul 25, 2022 at 7:43

Your Answer

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

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