{"id":21428926,"url":"https://github.com/notcoffee418/nethereum.contracts.multicall2","last_synced_at":"2025-07-19T08:32:30.723Z","repository":{"id":87668952,"uuid":"450897178","full_name":"NotCoffee418/Nethereum.Contracts.MultiCall2","owner":"NotCoffee418","description":"Multicall2 tryAggregate() support for Nethereum","archived":false,"fork":false,"pushed_at":"2022-02-12T12:30:58.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-27T23:03:15.694Z","etag":null,"topics":["cryptocurrency","nethereum","web3"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NotCoffee418.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2022-01-22T18:07:53.000Z","updated_at":"2022-01-24T11:06:56.000Z","dependencies_parsed_at":null,"dependency_job_id":"f5db1582-efbf-42dd-af94-17eef8ee14f7","html_url":"https://github.com/NotCoffee418/Nethereum.Contracts.MultiCall2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/NotCoffee418/Nethereum.Contracts.MultiCall2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FNethereum.Contracts.MultiCall2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FNethereum.Contracts.MultiCall2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FNethereum.Contracts.MultiCall2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FNethereum.Contracts.MultiCall2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NotCoffee418","download_url":"https://codeload.github.com/NotCoffee418/Nethereum.Contracts.MultiCall2/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NotCoffee418%2FNethereum.Contracts.MultiCall2/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265904823,"owners_count":23846692,"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":["cryptocurrency","nethereum","web3"],"created_at":"2024-11-22T22:15:15.310Z","updated_at":"2025-07-19T08:32:30.715Z","avatar_url":"https://github.com/NotCoffee418.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Nuget](https://img.shields.io/nuget/v/NotCoffee418.Nethereum.Contracts.MultiCall2?style=for-the-badge \"Nuget\")](https://www.nuget.org/packages/NotCoffee418.Nethereum.Contracts.MultiCall2)\n# Nethereum.Contracts.MultiCall2\nMulticall2 tryAggregate() support for Nethereum\n\n# Features\nThis is very similar to the official Nethereum's Multicall, however, the `TFunctionOutput` here contains a `bool? Success` property to indicate if a single call has failed (false), not been completed yet (null), or succeeded (true).  \n\nAdditionally, the whole call won't fail when a single contract call in your multicall fails.  \nInstead you still get valid results for all calls which did succeed.\n\n### Example usage\nThis code will use Multicall2 to get the Symbol and Decimals from a list of ERC20 tokens.  \nWhen the ERC20 token was able to be successfully recovered, we parse it into a DexToken object.\n\n\n```csharp\nusing Nethereum.Contracts.QueryHandlers.MultiCall2;\n\n/// \u003csummary\u003e\n/// Returns a list of DexToken info\n/// \u003cpoolAddress\u003e\n/// \u003c/summary\u003e\n/// \u003creturns\u003e\u003c/returns\u003e\npublic async Task\u003cList\u003cDexToken\u003e\u003e BulkGetTokenInfo(List\u003cstring\u003e tokenAddresses)\n{\n    // Run symbol requests\n    var tokenAddressAndSymbolInput = tokenAddresses\n        .Select(x =\u003e (x, new SymbolFunctionMessage()))\n        .ToList();\n    var symbolsResults = await RunMulticall\u003cSymbolFunctionMessage, SymbolOutputDTO\u003e(\n        tokenAddressAndSymbolInput, 500);\n\n    // Run decimals request\n    var tokenAddressAndDecimalsInput = tokenAddresses\n        .Select(x =\u003e (x, new DecimalsFunctionMessage()))\n        .ToList();\n    var decimalsResult = await RunMulticall\u003cDecimalsFunctionMessage, DecimalsOutputDTO\u003e(\n        tokenAddressAndDecimalsInput, 500);\n\n    // Generate result\n    List\u003cDexToken\u003e result = new List\u003cDexToken\u003e();\n    for (int i = 0; i \u003c tokenAddresses.Count; i++)\n    {\n        // Item1: Input Function Message\n        // Item2: Output Data\n        // Item3: Is Successful bool\n        if (decimalsResult[i].Item3 \u0026\u0026 symbolsResults[i].Item3) // if success\n            result.Add(new DexToken()\n            {\n                TokenAddress = tokenAddresses[i],\n                Decimals = decimalsResult[i].Item2.Decimals,\n                Shortname = symbolsResults[i].Item2.Symbol\n            });\n    }            \n    return result;\n}\n\n/// \u003csummary\u003e\n/// Runs a multicall with one or more contracts, different functions allowed.\n/// Length is irrelevant as you can use chunkSize to limit how many calls are made in one go.\n/// \u003c/summary\u003e\n/// \u003ctypeparam name=\"TFunctionMessage\"\u003eMust be FunctionMessage\u003c/typeparam\u003e\n/// \u003ctypeparam name=\"TFunctionOutput\"\u003eMust be IFunctionOutputDTO\u003c/typeparam\u003e\n/// \u003cparam name=\"inputs\"\u003elist of FunctionMessage\u003c/param\u003e\n/// \u003cparam name=\"chunkSize\"\u003ehow many queries to run in one call\u003c/param\u003e\n/// \u003creturns\u003eReturns mapped input and output for every functionmessage\u003c/returns\u003e\npublic async Task\u003cList\u003c(TFunctionMessage, TFunctionOutput, bool)\u003e\u003e\n    RunMulticall\u003cTFunctionMessage, TFunctionOutput\u003e(\n    List\u003c(string, TFunctionMessage)\u003e addressesAndInputs, int chunkSize = 100)\n    where TFunctionMessage : FunctionMessage, new()\n    where TFunctionOutput : IFunctionOutputDTO, new()\n{\n    // You can find a Multicall2 contract address for your chain here:\n    // https://github.com/makerdao/multicall\n    string multiCall2ContractAddress = \"0x5ba1e12693dc8f9c48aad8770482f4739beed696\";\n\n    // Endpoint for your chain\n    Uri endpointUri = new Uri(\"https://mainnet.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161\");\n\n    // Prep handlers\n    var client = new RpcClient(endpointUri);\n    var web3 = new Web3(client);\n    var multiQueryHandler = web3.Eth.GetMulti2QueryHandler(multiCall2ContractAddress);\n\n    // map to MulticallInputOutput\n    List\u003c(TFunctionMessage, Multicall2InputOutput\u003cTFunctionMessage, TFunctionOutput\u003e)[]\u003e chunks =\n        addressesAndInputs.Select(x =\u003e (x.Item2, new Multicall2InputOutput\u003cTFunctionMessage, TFunctionOutput\u003e(x.Item2, x.Item1)))\n        .ToArray()\n        .Chunk(chunkSize)\n        .ToList();\n\n    // Run multicalls\n    foreach (var chunkMulticallInputOutputs in chunks) \n        await multiQueryHandler.MultiCall2Async(chunkMulticallInputOutputs.Select(x =\u003e x.Item2).ToArray());\n\n    // Extract data and return\n    List\u003c(TFunctionMessage, TFunctionOutput, bool)\u003e result = new();\n    foreach (var chunk in chunks)\n        foreach (var data in chunk)\n            result.Add((data.Item1, data.Item2.Output, data.Item2.Success.Value));\n    return result;\n}\n\n// Function input and output defintions\n[Function(\"symbol\", \"string\")]\npublic class SymbolFunctionMessage : FunctionMessage { }\n\n[FunctionOutput]\npublic class SymbolOutputDTO : IFunctionOutputDTO\n{\n    [Parameter(\"string\")] public string Symbol { get; set; }\n}\n\n[Function(\"decimals\", \"uint8\")]\npublic class DecimalsFunctionMessage : FunctionMessage { }\n\n[FunctionOutput]\npublic class DecimalsOutputDTO : IFunctionOutputDTO\n{\n    [Parameter(\"uint8\")] public int Decimals { get; set; }\n}\n\n// Output object\npublic class DexToken : IEquatable\u003cDexToken\u003e\n{\n    public string Shortname { get; set; }\n    public string TokenAddress { get; set; }\n    public int Decimals { get; set; }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotcoffee418%2Fnethereum.contracts.multicall2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnotcoffee418%2Fnethereum.contracts.multicall2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnotcoffee418%2Fnethereum.contracts.multicall2/lists"}