{"id":25514453,"url":"https://github.com/greg-schrammel/multicall-provider","last_synced_at":"2025-04-10T18:23:21.286Z","repository":{"id":65929520,"uuid":"602685493","full_name":"greg-schrammel/multicall-provider","owner":"greg-schrammel","description":"Enchance your ethers provider with auto multicall aggregation","archived":false,"fork":false,"pushed_at":"2023-04-20T03:32:24.000Z","size":202,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-04-24T15:13:24.075Z","etag":null,"topics":["ethers","wagmi"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/multicall-provider","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/greg-schrammel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-02-16T18:22:10.000Z","updated_at":"2024-02-21T14:59:35.000Z","dependencies_parsed_at":null,"dependency_job_id":"5025056c-4e9a-4a93-8cc2-9180309cddd4","html_url":"https://github.com/greg-schrammel/multicall-provider","commit_stats":{"total_commits":26,"total_committers":1,"mean_commits":26.0,"dds":0.0,"last_synced_commit":"234a5da6363215fa1b64e30a8d5b82c14f2cd81d"},"previous_names":["greg-schrammel/with-multicall"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-schrammel%2Fmulticall-provider","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-schrammel%2Fmulticall-provider/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-schrammel%2Fmulticall-provider/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/greg-schrammel%2Fmulticall-provider/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/greg-schrammel","download_url":"https://codeload.github.com/greg-schrammel/multicall-provider/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248270598,"owners_count":21075795,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ethers","wagmi"],"created_at":"2025-02-19T12:18:38.376Z","updated_at":"2025-04-10T18:23:21.266Z","avatar_url":"https://github.com/greg-schrammel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# multicall-provider\n\nSave in your infura bills, aggreate multiple transactions in a single rpc call, with no extra effort\n\nInspired by [`0xsequence/multicall`](https://github.com/0xsequence/sequence.js/tree/master/packages/multicall), It works by wrapping an `ethers` provider and overrides the `call` method to aggregate supported transactions into a single [multicall3](https://github.com/mds1/multicall) call\n\n```bash\nnpm install multicall-provider\n\nyarn add multicall-provider\n\npnpm add multicall-provider\n```\n\n## Usage\n\n- It implements a buffer with a configurable 50ms delay and aggregates all operations received within that window\n- Calls targeting different block heights (`blockTags`) are aggregated based on the blockTag\n- Transactions including `from`, `value` or `gasPrice` skip aggregation and are forwarded to the underlying provider\n\n```ts\nconst provider = multicallProvider(new providers.JsonRpcProvider(...), {\n  batchSize: 25, // max amount of transactions per multicall call\n  timeWindow: 0, // time in ms to wait for new transactions before sending (0 still gets all from current event loop which is probably enough on most cases)\n  multicall3: '' // multicall3 contract address, only the aggregate3 method is used\n})\n```\n\nkeep in mind it works as long as there are no `await`'s between calls\n\n```ts\n// calls won't be aggregated\nconst daiDecimals = await dai.decimals()\nconst daiBalance = await dai.balanceOf('0x507f0daa42b215273b8a063b092ff3b6d27767af')\n\n// will be aggreated into a single rpc call\nconst [daiDecimals, daiBalance] = await Promise.all([\n  dai.decimals(),\n  dai.balanceOf('0x507f0daa42b215273b8a063b092ff3b6d27767af'),\n])\n\n// this way works too\nconst daiDecimals = dai.decimals()\nconst daiBalance = dai.balanceOf('0x507f0daa42b215273b8a063b092ff3b6d27767af')\n\nconst balance = await balancePromise\nconst supply = await supplyPromise\n```\n\n### Usage with Wagmi\n\nA util to wrap your `wagmi` provider with multicall is under `multicall-provider/wagmi` as follows\n\n```ts\nimport { configureChains, createClient, mainnet, WagmiConfig } from 'wagmi'\nimport { publicProvider } from '@wagmi/core/providers/public'\nimport { MetaMaskConnector } from '@wagmi/core/connectors/metaMask'\n\nimport { multicallProvider } from 'multicall-provider/wagmi'\n\nconst { chains, provider } = configureChains([mainnet], [publicProvider()])\n\nconst client = createClient({\n  provider: multicallProvider(provider),\n  connectors: [new MetaMaskConnector({ chains })],\n})\n```\n\nAll `useContractRead`s will be aggregated, but `useContractWrite`s won't\n\n### Why\n\nImagine you're building an app like\n\n```jsx\nconst App = () =\u003e {\n  return (\n    \u003c\u003e\n      \u003cUserBalance token=\"dai\" /\u003e\n      \u003cUserBalance token=\"usdc\" /\u003e\n      \u003cUserBalance token=\"usdt\" /\u003e\n    \u003c/\u003e\n  )\n}\n```\n\nInside each `\u003cUserBalance/\u003e` you have a `useContractRead` to fetch the balance of the token.\n\nThis app would start by making 3 different rpc calls, you may see how this grows depending on your app.\n\nYou could `useContractReads` on the parent and pass the balances down.\n\nbut what if you also need to use the Dai balance in another place way down the tree?  \nI mean the closer to the component using the data the better\n\nwrapping your wagmi provider with `multicallProvider`, you don't need to worry about that, need to use the Dai balance down the tree? `wagmi` will have it cached for you already, because of the first `useContractRead`, gg\n\n### Potential Issues\n\n`batchSize`: eth_call has a timeout restriction at node level, if it fails with a node error, consider lowering your batch size, 50 should be fine tho\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-schrammel%2Fmulticall-provider","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgreg-schrammel%2Fmulticall-provider","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgreg-schrammel%2Fmulticall-provider/lists"}