public WonkaEthEIP20TransferTrigger(Web3 poWeb3, EIP20Deployment moDeployData, string psContractAddress, string psReceiverAddress, long pnTransferAmount, CancellationTokenSource poCancelToken = null) : base(poWeb3, psContractAddress, poCancelToken) { mnTotalSupply = Convert.ToInt64(moDeployData.InitialAmount); mnTransferAmt = pnTransferAmount; msTokenName = moDeployData.TokenName; msTokenSymbol = moDeployData.TokenSymbol; msReceiverAddress = psReceiverAddress; moEIP20Service = new StandardTokenService(poWeb3, psContractAddress); moContract = moEIP20Service.ContractHandler; }
static async Task deployERC20() { var _account = new Account("fbde582d0deb10b30d0c1be8752650a9f4fc12c705610cb754b7ae3b0a2d4aa7", 5777); // var account = new Account(privatekey, Nethereum.Signer.Chain.MainNet); var _web3 = new Web3(_account, "http://127.0.0.1:7545"); _web3.TransactionManager.UseLegacyAsDefault = true; ulong totalSupply = 2000000; var deploymentContract = new EIP20Deployment() { InitialAmount = totalSupply, TokenName = "TestToken", TokenSymbol = "TT" }; var tokenService = await StandardTokenService.DeployContractAndWaitForReceiptAsync(_web3, deploymentContract); Console.WriteLine("Contract Address: " + tokenService.ContractAddress); }
public WonkaEthEIP20TransferTrigger(Web3 poWeb3, long pnTotalSupply, string psTokenName, string psTokenSymbol, string psReceiverAddress, long pnTransferAmount, CancellationTokenSource poCancelToken = null) : base(poWeb3, poCancelToken) { mnTotalSupply = pnTotalSupply; mnTransferAmt = pnTransferAmount; msTokenName = psTokenName; msTokenSymbol = psTokenSymbol; msReceiverAddress = psReceiverAddress; var deploymentContract = new EIP20Deployment() { InitialAmount = new System.Numerics.BigInteger(pnTotalSupply), TokenName = psTokenName, TokenSymbol = psTokenSymbol }; moEIP20Service = StandardTokenService.DeployContractAndGetServiceAsync(poWeb3, deploymentContract).Result; moContract = moEIP20Service.ContractHandler; }
public async void Test() { var senderAddress = AccountFactory.Address; var web3 = _ethereumClientIntegrationFixture.GetWeb3(); var deploymentMessage = new EIP20Deployment { InitialAmount = 10000, FromAddress = senderAddress, TokenName = "TST", TokenSymbol = "TST" }; var deploymentHandler = web3.Eth.GetContractDeploymentHandler <EIP20Deployment>(); var transactionReceipt = await deploymentHandler.SendRequestAndWaitForReceiptAsync(deploymentMessage) .ConfigureAwait(false); var contractAddress = transactionReceipt.ContractAddress; var newAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe"; var transactionMessage = new TransferFunction { FromAddress = senderAddress, To = newAddress, TokenAmount = 1000, }; var transferHandler = web3.Eth.GetContractTransactionHandler <TransferFunction>(); var transferReceipt = await transferHandler.SendRequestAndWaitForReceiptAsync(contractAddress, transactionMessage) .ConfigureAwait(false); await EventAssertionsAsync(contractAddress, web3.Client, senderAddress, newAddress); await EventAssertionsAsync(null, web3.Client, senderAddress, newAddress); }
//Sample of new features / requests public IEnumerator DeployAndTransferToken() { var url = "http://localhost:8545"; var privateKey = "0xb5b1870957d373ef0eeffecc6e4812c0fd08f554b37b233526acc331bf1544f7"; var account = "0x12890d2cce102216644c59daE5baed380d84830c"; //initialising the transaction request sender var transactionRequest = new TransactionSignedUnityRequest(url, privateKey); var deployContract = new EIP20Deployment() { InitialAmount = 10000, FromAddress = account, TokenName = "TST", TokenSymbol = "TST" }; //deploy the contract and True indicates we want to estimate the gas yield return(transactionRequest.SignAndSendDeploymentContractTransaction <EIP20DeploymentBase>(deployContract)); if (transactionRequest.Exception != null) { Debug.Log(transactionRequest.Exception.Message); yield break; } var transactionHash = transactionRequest.Result; Debug.Log("Deployment 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)); var deploymentReceipt = transactionReceiptPolling.Result; Debug.Log("Deployment contract address:" + deploymentReceipt.ContractAddress); //Query request using our acccount and the contracts address (no parameters needed and default values) var queryRequest = new QueryUnityRequest <BalanceOfFunction, BalanceOfFunctionOutput>(url, account); yield return(queryRequest.Query(new BalanceOfFunction() { Owner = account }, deploymentReceipt.ContractAddress)); //Getting the dto response already decoded var dtoResult = queryRequest.Result; Debug.Log(dtoResult.Balance); var transactionTransferRequest = new TransactionSignedUnityRequest(url, privateKey); var newAddress = "0xde0B295669a9FD93d5F28D9Ec85E40f4cb697BAe"; var transactionMessage = new TransferFunction { FromAddress = account, To = newAddress, Value = 1000, }; yield return(transactionTransferRequest.SignAndSendTransaction(transactionMessage, deploymentReceipt.ContractAddress)); var transactionTransferHash = transactionTransferRequest.Result; Debug.Log("Transfer txn hash:" + transactionHash); transactionReceiptPolling = new TransactionReceiptPollingRequest(url); yield return(transactionReceiptPolling.PollForReceipt(transactionTransferHash, 2)); var transferReceipt = transactionReceiptPolling.Result; var transferEvent = transferReceipt.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from event: " + transferEvent[0].Event.Value); var getLogsRequest = new EthGetLogsUnityRequest(url); var eventTransfer = TransferEventDTO.GetEventABI(); yield return(getLogsRequest.SendRequest(eventTransfer.CreateFilterInput(deploymentReceipt.ContractAddress, account))); var eventDecoded = getLogsRequest.Result.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from get logs event: " + eventDecoded[0].Event.Value); }
public static async Task <StandardTokenService> DeployContractAndGetServiceAsync(Web3.Web3 web3, EIP20Deployment eIP20Deployment, CancellationTokenSource cancellationTokenSource = null) { var receipt = await DeployContractAndWaitForReceiptAsync(web3, eIP20Deployment, cancellationTokenSource) .ConfigureAwait(false); return(new StandardTokenService(web3, receipt.ContractAddress)); }
public static Task <string> DeployContractAsync(Web3.Web3 web3, EIP20Deployment eIP20Deployment) { return(web3.Eth.GetContractDeploymentHandler <EIP20Deployment>().SendRequestAsync(eIP20Deployment)); }
public static Task <TransactionReceipt> DeployContractAndWaitForReceiptAsync(Web3.Web3 web3, EIP20Deployment eIP20Deployment, CancellationTokenSource cancellationTokenSource = null) { return(web3.Eth.GetContractDeploymentHandler <EIP20Deployment>() .SendRequestAndWaitForReceiptAsync(eIP20Deployment, cancellationTokenSource)); }
public async void Test() { var addressOwner = EthereumClientIntegrationFixture.AccountAddress; var web3 = _ethereumClientIntegrationFixture.GetWeb3(); ulong totalSupply = 1000000; var newAddress = "0x12890d2cce102216644c59daE5baed380d84830e"; var deploymentContract = new EIP20Deployment() { InitialAmount = totalSupply, TokenName = "TestToken", TokenSymbol = "TST" }; var tokenService = await StandardTokenService.DeployContractAndGetServiceAsync(web3, deploymentContract); var transfersEvent = tokenService.GetTransferEvent(); var totalSupplyDeployed = await tokenService.TotalSupplyQueryAsync(); Assert.Equal(totalSupply, totalSupplyDeployed); var tokenName = await tokenService.NameQueryAsync(); Assert.Equal("TestToken", tokenName); var tokenSymbol = await tokenService.SymbolQueryAsync(); Assert.Equal("TST", tokenSymbol); var ownerBalance = await tokenService.BalanceOfQueryAsync(addressOwner); Assert.Equal(totalSupply, ownerBalance); var transferReceipt = await tokenService.TransferRequestAndWaitForReceiptAsync(newAddress, 1000); ownerBalance = await tokenService.BalanceOfQueryAsync(addressOwner); Assert.Equal(totalSupply - 1000, ownerBalance); var newAddressBalance = await tokenService.BalanceOfQueryAsync(newAddress); Assert.Equal(1000, newAddressBalance); var allTransfersFilter = await transfersEvent.CreateFilterAsync(new BlockParameter(transferReceipt.BlockNumber)); var eventLogsAll = await transfersEvent.GetAllChangesAsync(allTransfersFilter); Assert.Single(eventLogsAll); var transferLog = eventLogsAll.First(); Assert.Equal(transferLog.Log.TransactionIndex.HexValue, transferReceipt.TransactionIndex.HexValue); Assert.Equal(transferLog.Log.BlockNumber.HexValue, transferReceipt.BlockNumber.HexValue); Assert.Equal(transferLog.Event.To.ToLower(), newAddress.ToLower()); Assert.Equal(transferLog.Event.Value, (ulong)1000); var approveTransactionReceipt = await tokenService.ApproveRequestAndWaitForReceiptAsync(newAddress, 1000); var allowanceAmount = await tokenService.AllowanceQueryAsync(addressOwner, newAddress); Assert.Equal(1000, allowanceAmount); }
public static async Task <StandardTokenService> DeployContractAndGetServiceAsync(Web3.Web3 web3, EIP20Deployment eIP20Deployment, CancellationToken cancellationToken = default(CancellationToken)) { var receipt = await DeployContractAndWaitForReceiptAsync(web3, eIP20Deployment, cancellationToken); return(new StandardTokenService(web3, receipt.ContractAddress)); }
public static Task <string> DeployContractAsync(Web3.Web3 web3, EIP20Deployment eIP20Deployment, CancellationToken cancellationToken = default(CancellationToken)) { return(web3.Eth.GetContractDeploymentHandler <EIP20Deployment>().SendRequestAsync(eIP20Deployment, cancellationToken)); }
//Sample of new features / requests public IEnumerator DeployAndTransferToken() { var url = "http://localhost:8545"; var privateKey = "0xa5ca770c997e53e182c5015bcf1b58ba5cefe358bf217800d8ec7d64ca919edd"; var account = "0x47E95DCdb798Bc315198138bC930758E6f399f81"; //initialising the transaction request sender var transactionRequest = new TransactionSignedUnityRequest(url, privateKey, account); var deployContract = new EIP20Deployment() { InitialAmount = 10000, FromAddress = account, TokenName = "TST", TokenSymbol = "TST" }; //deploy the contract and True indicates we want to estimate the gas yield return(transactionRequest.SignAndSendDeploymentContractTransaction <EIP20DeploymentBase>(deployContract)); if (transactionRequest.Exception != null) { Debug.Log(transactionRequest.Exception.Message); yield break; } var transactionHash = transactionRequest.Result; Debug.Log("Deployment 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)); var deploymentReceipt = transactionReceiptPolling.Result; Debug.Log("Deployment contract address:" + deploymentReceipt.ContractAddress); //Query request using our acccount and the contracts address (no parameters needed and default values) var queryRequest = new QueryUnityRequest <BalanceOfFunction, BalanceOfFunctionOutput>(url, account); yield return(queryRequest.Query(new BalanceOfFunction() { Owner = account }, deploymentReceipt.ContractAddress)); //Getting the dto response already decoded var dtoResult = queryRequest.Result; Debug.Log(dtoResult.Balance); var transactionTransferRequest = new TransactionSignedUnityRequest(url, privateKey, account); var newAddress = "0x4e70A9177Aff5077217f069E582992f7F9bec945"; var transactionMessage = new TransferFunction { FromAddress = account, To = newAddress, Value = 1000, }; yield return(transactionTransferRequest.SignAndSendTransaction(transactionMessage, deploymentReceipt.ContractAddress)); var transactionTransferHash = transactionTransferRequest.Result; Debug.Log("Transfer txn hash:" + transactionHash); transactionReceiptPolling = new TransactionReceiptPollingRequest(url); yield return(transactionReceiptPolling.PollForReceipt(transactionTransferHash, 2)); var transferReceipt = transactionReceiptPolling.Result; var transferEvent = transferReceipt.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from event: " + transferEvent[0].Event.Value); var getLogsRequest = new EthGetLogsUnityRequest(url); var eventTransfer = TransferEventDTO.GetEventABI(); yield return(getLogsRequest.SendRequest(eventTransfer.CreateFilterInput(deploymentReceipt.ContractAddress, account))); var eventDecoded = getLogsRequest.Result.DecodeAllEvents <TransferEventDTO>(); Debug.Log("Transferd amount from get logs event: " + eventDecoded[0].Event.Value); }