question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Custom block number

See original GitHub issue

Love the library, thank you for sharing!

Is there any way to request information from a specific block number? this example code gets your token balance from 4 days ago compared to now

    const blocksAgo = n => provider.getBlockNumber().then(b => b - n);
    let blockNumber = await blocksAgo(30000);

    const tokenContract = new Contract(tokenAddress, erc20Abi);
    let balance1 = await tokenContract.balanceOf(address, 'latest');
    console.log(`latestBalance: ${ethers.utils.formatEther(balance1)}`);
    let balance2 = await tokenContract.balanceOf(address, blockNumber);
    console.log(`prevBalance: ${ethers.utils.formatEther(balance2)}`);

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
daryledesilvacommented, Mar 7, 2022

second this. i use moralis archive node to lookup historical data. im running out of requests because i cant use non-latest blocks for multicalls, is this option introduced in some branch that’s not released yet?

put a block number on ContractCallContext object now it be the default latest

@joshstevens19 this sounds good, doesn’t need to be a global option. but atleast the functionality is there on a granular level for those who need it

awesome package btw, my favorite muticall package!

EDIT forked the repo and this works for me now https://github.com/daryledesilva/ethereum-multicall/commit/017ad2c144c0ea1494bc3083f8f99cd61d6a7af3#diff-dce38be9bbc70841ebcc4df53e419e5635cc6d7acd355bc2c6093e8fbd24cf74R355-R356 if there’s an official fix ill use that next time 😃

EDIT so i just need to init 2 multicall instances (one using latest block, one using a nearest block to today minus 1 day)

const multicall = new Multicall({
    web3Instance: web3,
    tryAggregate: true,
});
const multicall_yesterday = new Multicall({
    web3Instance: web3_archive,
    tryAggregate: true,
    defaultBlock: blockYesterday.data.result,
});

still better than nothing. max 2 calls atleast haha

1reaction
joshstevens19commented, Sep 3, 2021

Yes pass 0x0 it actually be really good if that logic was in that library balances you just sent if you wanted to do a PR to add this contract call to bring back the eth balances alongside the tokens that make that library even cooler !! If not il take a look when I get some time!

Thanks so much for your kind words dude!!! I try my best - I see your open source work as well mate so thank you as well! I have used your binance API which is just 🔥🔥🔥🔥

oh jeeeze that is not very nice way of them making you write this logic, much easier just passing addresses and getting it back.

Defo adding that contract call to get the eth value back in the balances multicall lib above will be a huge benefit as said welcome to do a PR for that if you wanted!!

thanks dude!!!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Custom call blocking | Home Phone - Ooma Support
Custom call blocking lets you create a list of phone numbers and caller-ID names that you simply don't want to hear from. You...
Read more >
Create a custom block - Drupal
This way you can add any number of instances of the custom block anywhere on your site.
Read more >
Design and Create a Custom Block - MATLAB & Simulink
Build a custom block using a Level-2 MATLAB S-function. ... The setup function initializes the number of input ports based on the values...
Read more >
Define Blocks | Blockly - Google Developers
Blockly provides a number of built-in fields, including text inputs, color pickers, and images. You can also create your own fields. → More...
Read more >
How to create a custom block - support? nTopology
Answer: This article uses a Custom Block to create our desired outcome. If you are new to using Custom Blocks, learn how to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found