public IEnumerator MakePayment( string server, string fromPrivateKey, string fromPublicAddress, string toPublicAddress, decimal sendAmount, int gas ) { var ethTransfer = new EthTransferUnityRequest(server, fromPrivateKey, fromPublicAddress); yield return(ethTransfer.TransferEther(toPublicAddress, sendAmount, gas)); if (ethTransfer.Exception != null) { Debug.Log(ethTransfer.Exception.Message); yield break; } var transactionHash = ethTransfer.Result; Debug.Log("Transfer transaction hash:" + transactionHash); // create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(server); // checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(transactionHash, 2)); Debug.Log("Transaction mined"); var balanceRequest = new EthGetBalanceUnityRequest(server); yield return(balanceRequest.SendRequest(toPublicAddress, BlockParameter.CreateLatest())); Debug.Log("Balance of account:" + UnitConversion.Convert.FromWei(balanceRequest.Result.Value)); }
// We create the function which will check the balance of the address and return a callback with a decimal variable public static IEnumerator getAccountBalance(string address, System.Action <decimal> callback) { // Now we define a new EthGetBalanceUnityRequest and send it the testnet url where we are going to // check the address, in this case "https://kovan.infura.io". // (we get EthGetBalanceUnityRequest from the Netherum lib imported at the start) var getBalanceRequest = new EthGetBalanceUnityRequest(ETH_ENDPOINT); // Then we call the method SendRequest() from the getBalanceRequest we created // with the address and the newest created block. yield return(getBalanceRequest.SendRequest(address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); // Now we check if the request has an exception if (getBalanceRequest.Exception == null) { // We define balance and assign the value that the getBalanceRequest gave us. var balance = getBalanceRequest.Result.Value; // Finally we execute the callback and we use the Netherum.Util.UnitConversion // to convert the balance from WEI to ETHER (that has 18 decimal places) callback(Nethereum.Util.UnitConversion.Convert.FromWei(balance, 18)); } else { // If there was an error we just throw an exception. throw new System.InvalidOperationException("Get balance request failed"); } }
public IEnumerator TransferEther(string url, string privateKey, string addressTo, string amountText) { var amount = System.Decimal.Parse(amountText); var ethTransfer = new EthTransferUnityRequest(url, privateKey); var receivingAddress = addressTo; var gasPriceGwei = 2; yield return(ethTransfer.TransferEther(receivingAddress, amount, gasPriceGwei)); if (ethTransfer.Exception != null) { Debug.Log(ethTransfer.Exception.Message); yield break; } var transactionHash = ethTransfer.Result; Debug.Log("Transfer transaction hash:" + transactionHash); //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(transactionHash, 2)); Debug.Log("Transaction mined"); var balanceRequest = new EthGetBalanceUnityRequest(url); yield return(balanceRequest.SendRequest(receivingAddress, BlockParameter.CreateLatest())); var balanceAddressTo = UnitConversion.Convert.FromWei(balanceRequest.Result.Value); Debug.Log("Balance of account:" + balanceAddressTo); }
public IEnumerator CheckAccountBalanceCoroutine(string address) { EtherBalanceText.text = "Loading Balance..."; CustomTokenBalanceText.text = ""; yield return(0); // allow UI to update var getBalanceRequest = new EthGetBalanceUnityRequest(networkUrl); string etherBalance; string customTokenBalance; yield return(getBalanceRequest.SendRequest(address, BlockParameter.CreateLatest())); if (getBalanceRequest.Exception == null) { etherBalance = UnitConversion.Convert.FromWei(getBalanceRequest.Result.Value).ToString(); } else { throw new System.InvalidOperationException("Get balance request failed"); } var tokenBalanceRequest = new EthCallUnityRequest(networkUrl); // get custom token balance (uint 256) yield return(tokenBalanceRequest.SendRequest(TokenContractService.Instance.CreateCallInput("balanceOf", address), BlockParameter.CreateLatest())); customTokenBalance = UnitConversion.Convert.FromWei( TokenContractService.Instance.DecodeVariable <BigInteger>("balanceOf", tokenBalanceRequest.Result), TokenContractService.Instance.TokenInfo.decimals).ToString(); EtherBalanceText.text = "ETH: " + etherBalance; CustomTokenBalanceText.text = TokenContractService.Instance.TokenInfo.symbol + ": " + customTokenBalance; }
/// <summary> /// Gets the ether balance of a certain wallet. /// </summary> /// <param name="promise"> Promise of an eventual eth balance returned. </param> /// <param name="address"> The address to check the ether balance for. </param> /// <returns> The time waited for the request to complete. </returns> private static IEnumerator _AddressEthBalanceCoroutine(EthCallPromise <dynamic> promise, string address) { var request = new EthGetBalanceUnityRequest(EthereumNetworkManager.CurrentNetwork.NetworkUrl); yield return(request.SendRequest(address, BlockParameter.CreateLatest())); promise.Build(request, () => SolidityUtils.ConvertFromUInt(request.Result.Value, 18)); }
public IEnumerator GetBalance() { EthGetBalanceUnityRequest req = new EthGetBalanceUnityRequest(m_endpoint); yield return(req.SendRequest(m_addr, BlockParameter.CreateLatest())); Debug.Log("balance " + GetEthValue(req.Result.Value)); }
// Check Ether balance of the player account public IEnumerator GetAccountBalanceCoroutine() { var getBalanceRequest = new EthGetBalanceUnityRequest(networkUrl); // Send balance request with player's account, asking for balance in latest block yield return(getBalanceRequest.SendRequest(playerEthereumAccount, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getBalanceRequest.Exception == null) { var balance = getBalanceRequest.Result.Value; // Convert the balance from wei to ether and round to 8 decimals for display balanceG = Nethereum.Util.UnitConversion.Convert.FromWei(balance, 18).ToString("n8"); } }
public IEnumerator _GetBalance() { EthGetBalanceUnityRequest getBalance = new EthGetBalanceUnityRequest(url); yield return(getBalance.SendRequest(SaveData.Address, BlockParameter.CreateLatest())); HexBigInteger balance = getBalance.Result; SaveData.Balance = ETHUtils.IntegerToDecimal(decimal.Parse(balance.Value.ToString()), 18); Debug.Log("GetBalance ret:" + SaveData.Balance.ToString()); GetAdventureAndTop100(); IsGetBalance = false; Save(); }
//----------------------------------------------------------------------------------------------------------------- // GET BALANCE //----------------------------------------------------------------------------------------------------------------- public IEnumerator GetBalance(string address) { // get ETH balance var contractRequest = new EthGetBalanceUnityRequest(_url); yield return(contractRequest.SendRequest(address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); tokenManager.SetAccountTokenBalance(tokenManager.fungibleTokens[0].address, contractRequest.Result.Value); // get ERC20 balances (start from 1 because 0 is ETH) for (int i = 1; i < _erc20Readers.Length; ++i) { StartCoroutine(GetErc20Balance(i, address)); } }
public IEnumerator GetAccountBalance(string account, System.Action <float> callback) { var balanceRequest = new EthGetBalanceUnityRequest(Url); yield return(balanceRequest.SendRequest(account, BlockParameter.CreateLatest())); var ether = Web3.Convert.FromWei(balanceRequest.Result.Value); if (callback != null) { callback(decimal.ToSingle(ether)); } Logger("Balance is " + ether); }
public IEnumerator getAccountBalance(string address, System.Action <decimal> callback) { var getBalanceRequest = new EthGetBalanceUnityRequest(_url); yield return(getBalanceRequest.SendRequest(address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getBalanceRequest.Exception == null) { var balance = getBalanceRequest.Result.Value; callback(Nethereum.Util.UnitConversion.Convert.FromWei(balance, 18)); } else { throw new System.InvalidOperationException("Get balance request failed"); } }
public IEnumerator GetBalance(string address, System.Action <BigInteger> callback) { var url = RPCMgr.instance.Account.chain_url_; var get_balance = new EthGetBalanceUnityRequest(url, settings_); yield return(get_balance.SendRequest(address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (get_balance.Exception == null) { var balance = get_balance.Result.Value; callback(balance); } else { throw new System.InvalidOperationException("Get balance request failed"); } }
public static IEnumerator getAccountBalance(string address, System.Action <decimal> callback) { //--取得主網ETH餘額 var getBalanceRequest = new EthGetBalanceUnityRequest("https://testnet-rpc.tangerine-network.io"); yield return(getBalanceRequest.SendRequest(address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); if (getBalanceRequest.Exception == null) { var balance = getBalanceRequest.Result.Value; yield return(new WaitForSeconds(1)); callback(Nethereum.Util.UnitConversion.Convert.FromWei(balance, 18)); } else { throw new System.InvalidOperationException("取得TAN餘額失敗"); } }
//Sample of new features / requests public IEnumerator TransferEther(decimal Amount, string AddressTo) { //Url = InputUrl.text; //PrivateKey = InputPrivateKey.text; //AddressTo = InputAddressTo.text; //Amount = System.Decimal.Parse(InputAmount.text); //initialising the transaction request sender var ethTransfer = new EthTransferUnityRequest(Url, PrivateKey); var receivingAddress = AddressTo; yield return(ethTransfer.TransferEther(receivingAddress, Amount, GasPriceGwei)); if (ethTransfer.Exception != null) { Debug.Log(ethTransfer.Exception.Message); yield break; } TransactionHash = ethTransfer.Result; //ResultTxnHash.text = TransactionHash; Debug.Log("Transfer transaction hash:" + TransactionHash); //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(Url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(TransactionHash, 2)); Debug.Log("Transaction mined"); var balanceRequest = new EthGetBalanceUnityRequest(Url); yield return(balanceRequest.SendRequest(receivingAddress, BlockParameter.CreateLatest())); BalanceAddressTo = UnitConversion.Convert.FromWei(balanceRequest.Result.Value); //ResultBalanceAddressTo.text = BalanceAddressTo.ToString(); Debug.Log("Balance of account:" + BalanceAddressTo); }
public static IEnumerator getAccountBalance(string address, System.Action <decimal> callback) { var getBalanceRequest = new EthGetBalanceUnityRequest("https://kovan.infura.io"); yield return(getBalanceRequest.SendRequest(address, Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest())); // Now we check if the request has an exception if (getBalanceRequest.Exception == null) { // We define balance and assign the value that the getBalanceRequest gave us. var balance = getBalanceRequest.Result.Value; // Finally we execute the callback and we use the Netherum.Util.UnitConversion // to convert the balance from WEI to ETHER (that has 18 decimal places) callback(Nethereum.Util.UnitConversion.Convert.FromWei(balance, 18)); } else { // If there was an error we just throw an exception. throw new System.InvalidOperationException("Get balance request failed"); } }
// Send balance request using EthGetGalanceUnityRequest private static IEnumerator GetBalanceCoroutine(string address, UnityAction <decimal> onSucceed, UnityAction <System.Exception> onFailed) { // Use EthGetBalanceUnityRequest from the Nethereum lib to send balance request var balanceRequest = new EthGetBalanceUnityRequest(WalletSettings.current.networkUrl); // Then we call the method SendRequest() from the getBalanceRequest we created with the address and the newest created block yield return(balanceRequest.SendRequest(address, BlockParameter.CreateLatest())); // Now we check if the request has an exception if (balanceRequest.Exception == null) { // We define balance and assign the value that the getBalanceRequest gave us var balance = balanceRequest.Result.Value; // Finally we execute the callback and we use the Netherum.Util.UnitConversion // to convert the balance from WEI to ETHER (that has 18 decimal places) onSucceed?.Invoke(UnitConversion.Convert.FromWei(balance, 18)); } else { // If there was an error we just call the onFailed callback onFailed?.Invoke(balanceRequest.Exception); } }
//Sample of new features / requests public IEnumerator TransferEther() { var url = "http://localhost:8545"; var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"; var account = "0x12890d2cce102216644c59daE5baed380d84830c"; //initialising the transaction request sender var ethTransfer = new EthTransferUnityRequest(url, privateKey, account); var receivingAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe"; yield return(ethTransfer.TransferEther("0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe", 1.1m, 2)); if (ethTransfer.Exception != null) { Debug.Log(ethTransfer.Exception.Message); yield break; } var transactionHash = ethTransfer.Result; Debug.Log("Transfer transaction hash:" + transactionHash); //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(transactionHash, 2)); Debug.Log("Transaction mined"); var balanceRequest = new EthGetBalanceUnityRequest(url); yield return(balanceRequest.SendRequest(receivingAddress, BlockParameter.CreateLatest())); Debug.Log("Balance of account:" + UnitConversion.Convert.FromWei(balanceRequest.Result.Value)); }
//Sample of new features / requests public IEnumerator TransferEther() { var url = "http://localhost:8545"; var privateKey = "0xa5ca770c997e53e182c5015bcf1b58ba5cefe358bf217800d8ec7d64ca919edd"; var account = "0x47E95DCdb798Bc315198138bC930758E6f399f81"; //initialising the transaction request sender var ethTransfer = new EthTransferUnityRequest(url, privateKey, account); var receivingAddress = "0x09f8F8c219D94A5db8Ee466dC072748603A7A0D9"; yield return(ethTransfer.TransferEther("0x09f8F8c219D94A5db8Ee466dC072748603A7A0D9", 1.1m, 2)); if (ethTransfer.Exception != null) { Debug.Log(ethTransfer.Exception.Message); yield break; } var transactionHash = ethTransfer.Result; Debug.Log("Transfer transaction hash:" + transactionHash); //create a poll to get the receipt when mined var transactionReceiptPolling = new TransactionReceiptPollingRequest(url); //checking every 2 seconds for the receipt yield return(transactionReceiptPolling.PollForReceipt(transactionHash, 2)); Debug.Log("Transaction mined"); var balanceRequest = new EthGetBalanceUnityRequest(url); yield return(balanceRequest.SendRequest(receivingAddress, BlockParameter.CreateLatest())); Debug.Log("Balance of account:" + UnitConversion.Convert.FromWei(balanceRequest.Result.Value)); }