Skip to content

Commit

Permalink
Merge pull request #32 from ChainSafe/dynamic-multicall
Browse files Browse the repository at this point in the history
dynamic multicall for different chains and networks
  • Loading branch information
leon-do authored Nov 15, 2021
2 parents 0f2d7c7 + 16509a7 commit ca8d012
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Web3Unity/Scripts/Library/ERC721.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static async Task<string> OwnerOf(string _chain, string _network, string
return response;
}

public static async Task<List<string>> OwnerOfBatch(string _chain, string _network, string _contract, string[] _tokenIds, string _rpc="")
public static async Task<List<string>> OwnerOfBatch(string _chain, string _network, string _contract, string[] _tokenIds, string _multicall = "", string _rpc="")
{
string method = "ownerOf";
// build array of args
Expand All @@ -45,7 +45,7 @@ public static async Task<List<string>> OwnerOfBatch(string _chain, string _netwo
obj[i] = new string[1] { _tokenIds[i] };
};
string args = JsonConvert.SerializeObject(obj);
string response = await EVM.MultiCall(_chain, _network, _contract, abi, method, args, _rpc);
string response = await EVM.MultiCall(_chain, _network, _contract, abi, method, args, _multicall, _rpc);
try
{
string[] responses = JsonConvert.DeserializeObject<string[]>(response);
Expand Down
3 changes: 2 additions & 1 deletion Web3Unity/Scripts/Library/EVM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public static async Task<string> Call(string _chain, string _network, string _co
return data.response;
}

public static async Task<string> MultiCall(string _chain, string _network, string _contract, string _abi, string _method, string _args, string _rpc = "")
public static async Task<string> MultiCall(string _chain, string _network, string _contract, string _abi, string _method, string _args, string _multicall = "", string _rpc = "")
{
WWWForm form = new WWWForm();
form.AddField("chain", _chain);
Expand All @@ -64,6 +64,7 @@ public static async Task<string> MultiCall(string _chain, string _network, strin
form.AddField("abi", _abi);
form.AddField("method", _method);
form.AddField("args", _args);
form.AddField("multicall", _multicall);
form.AddField("rpc", _rpc);
string url = host + "/multicall";
UnityWebRequest webRequest = UnityWebRequest.Post(url, form);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ async void Start()
string network = "mainnet";
string contract = "0xA74E199990FF572A320508547Ab7f44EA51e6F28";
string[] tokenIds = {"700", "791"};
string multicall = ""; // optional: multicall contract https://github.com/makerdao/multicall
string rpc = ""; // optional: custom rpc

List<string> batchOwners = await ERC721.OwnerOfBatch(chain, network, contract, tokenIds);
List<string> batchOwners = await ERC721.OwnerOfBatch(chain, network, contract, tokenIds, multicall, rpc);
foreach (string owner in batchOwners)
{
print ("OwnerOfBatch: " + owner);
Expand Down

0 comments on commit ca8d012

Please sign in to comment.