private static async Task CardInfo() { var cardRoundAddress = await CsService.GetCardRoundQueryAsync(); var cardRoundService = new ScratchCardRoundService(web3, cardRoundAddress); var cardPrice = await cardRoundService.GetCardPriceQueryAsync(); Console.WriteLine($"The current Price of a card is: {Web3.Convert.FromWei(cardPrice)}"); var remainingPrizes = await cardRoundService.UnclaimedPrizesQueryAsync(); for (int i = 0; i < remainingPrizes.Num.Count; i++) { Console.WriteLine($"Remaining cards: {remainingPrizes.Num[i]}, with pay: {Web3.Convert.FromWei(remainingPrizes.Pays[i])}"); } Console.WriteLine(); }
private static async Task TransferRoundLink() { // Approving the contract to use link. var approveHandler = web3.Eth.GetContractTransactionHandler <ApproveFunction>(); var cardPrice = await RService.GetCardPriceQueryAsync(); Console.WriteLine($"Card price: {cardPrice}"); var totalRoundValue = (cardPrice * 250000) - await CsService.GetLinkBalanceQueryAsync(ScratchContractAddress); Console.WriteLine($"Total round value: {totalRoundValue}"); var approve = new ApproveFunction() { Spender = ScratchContractAddress, TokenAmount = totalRoundValue }; await approveHandler.SendRequestAndWaitForReceiptAsync("0xa36085F69e2889c224210F603D836748e7dC0088", approve); // Transfering link. var transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>(); var transfer = new TransferFunction() { To = ScratchContractAddress, TokenAmount = totalRoundValue }; Console.WriteLine($"Token amount: {transfer.TokenAmount} in wei"); var transactionReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync("0xa36085F69e2889c224210F603D836748e7dC0088", transfer); var linkBalance = await CsService.GetLinkBalanceQueryAsync(ScratchContractAddress); Console.WriteLine($"Contract Link Balance: {Web3.Convert.FromWei(linkBalance)}"); }
private static async Task BuyCard() { var accountEtherBalance = await web3.Eth.GetBalance.SendRequestAsync(account.Address); var accountLinkBalance = Web3.Convert.FromWei(await CsService.GetLinkBalanceQueryAsync(account.Address)); Console.WriteLine($" Account: {account.Address}\n Ether Balance: {Web3.Convert.FromWei(accountEtherBalance)}\n Link Balance: {accountLinkBalance}\n"); // Approving the contract to use 1 link. var approveHandler = web3.Eth.GetContractTransactionHandler <ApproveFunction>(); var approve = new ApproveFunction() { Spender = ScratchContractAddress, TokenAmount = Web3.Convert.ToWei(1) }; await approveHandler.SendRequestAndWaitForReceiptAsync("0xa36085F69e2889c224210F603D836748e7dC0088", approve); // Get Price of a card. //var LinkPrice = await CsService.RequestLinkPriceQueryAsync(); //var CardValue = Web3.Convert.FromWei((2000000000000000000 / LinkPrice) * 100000000); // Getting ScratchCardRound handler. var address = await CsService.GetCardRoundQueryAsync(); Console.WriteLine($"Card Round address: {address}"); ScratchCardRoundService RS = new ScratchCardRoundService(web3, address); var CardValue = Web3.Convert.FromWei(await RS.GetCardPriceQueryAsync() + 100000000000000000); Console.WriteLine($"Price of Card: {CardValue} \n"); Console.WriteLine("Buying card..."); // Generating a seed Random rand = new Random(); uint seed = (uint)rand.Next(); var buyCard = await CsService.BuyScatchCardRequestAndWaitForReceiptAsync(seed); // Getting the RequestID emited from the BuyScratchCard Request. var RequestID = buyCard.DecodeAllEvents <RequestIDEventDTO>()[0].Event.RequestId.ToHex(); //Console.WriteLine($"RequestID: {RequestID}"); /* * var fulfillHandler = CsService.ContractHandler.GetEvent<RequestFulfilledEventDTO>(); * * var filterFulfill = fulfillHandler.CreateFilterInput(); * * while (true) * { * var requests = await fulfillHandler.GetAllChanges(filterFulfill); * if(requests.Count > 0) * { * Console.WriteLine($"Raw Random Number: {requests[0].Event.Randomness}"); * break; * } * * }*/ var PrizeEventHandler = RS.ContractHandler.GetEvent <PrizeClaimEventDTO>(); var filterPrizeEvents = PrizeEventHandler.CreateFilterInput(); decimal prize = 0; // Getting the PrizeClaim event with the correct RequestID while (true) { var allRequestEvents = await PrizeEventHandler.GetAllChanges(filterPrizeEvents); if (allRequestEvents.Count > 0) { bool brk = false; foreach (EventLog <PrizeClaimEventDTO> e in allRequestEvents) { //Console.WriteLine($"Scratch Card result, Address: {e.Event.Player}, RequestID: {e.Event.RequestId.ToHex()}, Prize Number: {e.Event.Number}, Prize: {Web3.Convert.FromWei(e.Event.Prize)}\n"); if (e.Event.RequestId.ToHex().Equals(RequestID)) { Console.WriteLine($"Scratch Card result, Address: {e.Event.Player}, RequestID: {e.Event.RequestId.ToHex()}, Prize Number: {e.Event.Number}, Prize: {Web3.Convert.FromWei(e.Event.Prize)}\n"); prize = Web3.Convert.FromWei(e.Event.Prize); brk = true; } } if (brk) { break; } } } Console.WriteLine($"Initial Account Link Balance: {accountLinkBalance}, Card Value: {CardValue}, Prize value: {prize}"); Console.WriteLine($"Expected Link Balance: {accountLinkBalance - CardValue + prize}\n"); accountLinkBalance = Web3.Convert.FromWei(await CsService.GetLinkBalanceQueryAsync(account.Address)); Console.WriteLine($"Link Balance: {accountLinkBalance}\n"); var ScratchTokenAddress = await CsService.GetTokenQueryAsync(); ScratchTokenService tokenService = new ScratchTokenService(web3, ScratchTokenAddress); var ScratchTokenBalance = await tokenService.BalanceOfQueryAsync(account.Address); Console.WriteLine($"Scratch Token Balance: {ScratchTokenBalance}"); }