/
Program.cs
47 lines (39 loc) · 1.86 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using System;
using System.Numerics;
using System.Threading.Tasks;
using In3;
using In3.Configuration;
using In3.Eth1;
using In3.Utils;
namespace CallSmartContractFunction
{
public class Program
{
public static async Task Main()
{
// Set it to mainnet
IN3 mainnetClient = IN3.ForChain(Chain.Mainnet);
ClientConfiguration cfg = mainnetClient.Configuration;
cfg.Proof = Proof.Standard;
string contractAddress = "0x2736D225f85740f42D17987100dc8d58e9e16252";
// Create the query transaction
TransactionRequest serverCountQuery = new TransactionRequest();
serverCountQuery.To = contractAddress;
// Define the function and the parameters to query the total in3 servers
serverCountQuery.Function = "totalServers():uint256";
serverCountQuery.Params = new object[0];
string[] serverCountResult = (string[])await mainnetClient.Eth1.Call(serverCountQuery, BlockParameter.Latest);
BigInteger servers = DataTypeConverter.HexStringToBigint(serverCountResult[0]);
for (int i = 0; i < servers; i++)
{
TransactionRequest serverDetailQuery = new TransactionRequest();
serverDetailQuery.To = contractAddress;
// Define the function and the parameters to query the in3 servers detail
serverDetailQuery.Function = "servers(uint256):(string,address,uint32,uint256,uint256,address)";
serverDetailQuery.Params = new object[] { i }; // index of the server (uint256) as per solidity function signature
string[] serverDetailResult = (string[])await mainnetClient.Eth1.Call(serverDetailQuery, BlockParameter.Latest);
Console.Out.WriteLine($"Server url: {serverDetailResult[0]}");
}
}
}
}