Exemple #1
0
        static void Main(string[] args)
        {
            var provider        = "https://ropsten.infura.io/v3/'<PROJECT-ID>'";
            var contractAddress = "0x6aB06024E4bc1841C7Aa82D6f0833D29343503a6";
            var privateKey      = "0x'<PRIVATE-KEY>'";
            var abi             =
                "[{\"inputs\":[{\"internalType\":\"string\",\"name\":\"newFact\",\"type\":\"string\"}],\"name\":\"add\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"count\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"index\",\"type\":\"uint256\"}],\"name\":\"getFact\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"}]";

            ContractService contractService = new ContractService(provider, contractAddress, abi, privateKey);

            System.Console.WriteLine($"Stored facts in the contract: {contractService.GetTotalFacts()}");
            System.Console.WriteLine("Press Any Key To Exit...");
            System.Console.ReadLine();

            var index = 0;

            System.Console.WriteLine();
            System.Console.WriteLine($"Fact {index + 1}: {contractService.GetFact(index)}");
            System.Console.WriteLine();
            System.Console.WriteLine("Press Any Key To Exit...");
            System.Console.WriteLine();
            System.Console.ReadLine();

            var fact = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";

            System.Console.WriteLine();
            System.Console.WriteLine($"Transaction Hash: {contractService.AddFact(fact)}");
            System.Console.WriteLine();
            System.Console.WriteLine("Press Any Key To Exit...");
            System.Console.WriteLine();
            System.Console.ReadLine();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            var provider   = "https://ropsten.infura.io/v3/2c64faa795c242d083706a5e3105e830";
            var abi        = "[ { \"inputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"constructor\" }, { \"inputs\": [ { \"internalType\": \"string\", \"name\": \"newFact\", \"type\": \"string\" } ], \"name\": \"add\", \"outputs\": [], \"stateMutability\": \"nonpayable\", \"type\": \"function\" }, { \"inputs\": [], \"name\": \"count\", \"outputs\": [ { \"internalType\": \"uint256\", \"name\": \"\", \"type\": \"uint256\" } ], \"stateMutability\": \"view\", \"type\": \"function\" }, { \"inputs\": [ { \"internalType\": \"uint256\", \"name\": \"index\", \"type\": \"uint256\" } ], \"name\": \"getFact\", \"outputs\": [ { \"internalType\": \"string\", \"name\": \"\", \"type\": \"string\" } ], \"stateMutability\": \"view\", \"type\": \"function\" } ]";
            var address    = "0x9f4481052fd01f0e8d17ebac57d6ca8c62360f2c";
            var privateKey = "0x7EB2255581AED1C929A291B65BC3A37FB70BA8C6783FFFABE18D8C6EC5DCFFC1";

            ContractService contractService = new ContractService(provider, address, abi, privateKey);

            var fact = "The Times 03/Jan/2009 Chancellor on brink of second bailout for banks";

            System.Console.WriteLine($"Transaction Hash: {contractService.AddFact(fact)}");

            var index = 0;

            System.Console.WriteLine($"Fact {index}: {contractService.getFact(index)}");

            System.Console.WriteLine($"Stored facts in the contract: {contractService.GetTotalFacts()}");

            System.Console.WriteLine("Press Any Key to Exit...");
            System.Console.ReadLine();
        }