Example #1
0
        private static async Task Deploy()
        {
            Console.WriteLine("Deploying contract...");

            //GetBalance().Wait();

            ScratchDeployment SD = new ScratchDeployment
            {
                InitialLink = Web3.Convert.ToWei(1)
                              //AmountToSend = 100000000000
            };

            try
            {
                var deployReciept = await ScratchService.DeployContractAndWaitForReceiptAsync(web3, SD);

                ScratchContractAddress = deployReciept.ContractAddress;
                Console.WriteLine($"gas: {Web3.Convert.FromWei(Web3.Convert.ToWei(deployReciept.GasUsed, UnitConversion.EthUnit.Gwei))}");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            Console.WriteLine($"Scratch contract address: {ScratchContractAddress}");

            //var balance = await web3.Eth.GetBalance.SendRequestAsync(ScratchContractAddress);

            //Console.WriteLine($"Scratch contract Ether: {balance}");

            // Open Settings.
            var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            var Settings   = configFile.AppSettings.Settings;

            Settings["ScratchContractAddress"].Value = ScratchContractAddress;

            CsService = new ScratchService(web3, ScratchContractAddress);

            var rec1 = CsService.GetLinkBalanceQueryAsync(account.Address);

            Console.WriteLine($"Account Link Balance: {Web3.Convert.FromWei(rec1.Result)}\n Account Eth Balance: {Web3.Convert.FromWei(await web3.Eth.GetBalance.SendRequestAsync(account.Address))}");

            /*
             * var deposit = new DepositLinkFunction()
             * {
             *  Value = 1
             * };*/

            var transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>();
            var transfer        = new TransferFunction()
            {
                To          = ScratchContractAddress,
                TokenAmount = Web3.Convert.ToWei(1)
            };

            Console.WriteLine($"Token amount: {transfer.TokenAmount} in wei");

            var transactionReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync("0xa36085F69e2889c224210F603D836748e7dC0088", transfer);

            rec1 = CsService.GetLinkBalanceQueryAsync(ScratchContractAddress);

            Console.WriteLine($"Link sent to Contract: {Web3.Convert.FromWei(rec1.Result)}");

            RoundContractAddress = await CsService.GetCardRoundQueryAsync();

            Settings["RoundContractAddress"].Value = RoundContractAddress;

            RService = new ScratchCardRoundService(web3, RoundContractAddress);


            // Save Settings
            configFile.Save(ConfigurationSaveMode.Modified);

            ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);

            Console.WriteLine("\n");
        }
 public static Task <string> DeployContractAsync(Nethereum.Web3.Web3 web3, ScratchDeployment scratchDeployment)
 {
     return(web3.Eth.GetContractDeploymentHandler <ScratchDeployment>().SendRequestAsync(scratchDeployment));
 }
        public static async Task <ScratchService> DeployContractAndGetServiceAsync(Nethereum.Web3.Web3 web3, ScratchDeployment scratchDeployment, CancellationTokenSource cancellationTokenSource = null)
        {
            var receipt = await DeployContractAndWaitForReceiptAsync(web3, scratchDeployment, cancellationTokenSource);

            return(new ScratchService(web3, receipt.ContractAddress));
        }
 public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Nethereum.Web3.Web3 web3, ScratchDeployment scratchDeployment, CancellationTokenSource cancellationTokenSource = null)
 {
     return(web3.Eth.GetContractDeploymentHandler <ScratchDeployment>().SendRequestAndWaitForReceiptAsync(scratchDeployment, cancellationTokenSource));
 }