Last active
August 9, 2018 08:16
-
-
Save Enigmatic331/006ce75c1851296371793eb7827a05e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Private Async Sub testContract() | |
Dim privateKey As New Nethereum.Signer.EthECKey("") | |
Dim account = New Nethereum.Web3.Accounts.Account(privateKey) | |
' ABI and bytecode of the deployed contract | |
Dim abi = "[{""constant"":false,""inputs"":[{""name"":""val"",""type"":""uint256""}],""name"":""callTest"",""outputs"":[],""payable"":false,""stateMutability"":""nonpayable"",""type"":""function""},{""constant"":true,""inputs"":[],""name"":""number"",""outputs"":[{""name"":"""",""type"":""uint256""}],""payable"":false,""stateMutability"":""view"",""type"":""function""},{""anonymous"":false,""inputs"":[{""indexed"":false,""name"":""sender"",""type"":""address""},{""indexed"":false,""name"":""val"",""type"":""uint256""}],""name"":""raiseMe"",""type"":""event""}]" | |
Dim bytecode = "0x608060405234801561001057600080fd5b50610102806100206000396000f30060806040526004361060485763ffffffff7c01000000000000000000000000000000000000000000000000000000006000350416634cbe9d728114604d5780638381f58a146064575b600080fd5b348015605857600080fd5b5060626004356088565b005b348015606f57600080fd5b50607660d0565b60408051918252519081900360200190f35b6000805482019081905560408051338152602081019290925280517fef70134e1492bf63b4323b9ebdaafbe3c6e348d4611248d18b7b86b44f3c6ac99281900390910190a150565b600054815600a165627a7a723058203152a54992821f999cff225076ca98850e91c28eaa1c2756c3bfa7c478ab87400029" | |
Dim iweb3 = New Web3(account, "http://localhost:8545") | |
'Dim gas As New HexBigInteger(1000000) | |
Dim value As New HexBigInteger(0) | |
Dim gas As HexBigInteger = Await iweb3.Eth.DeployContract.EstimateGasAsync(abi, bytecode, account.Address, Nothing) | |
Dim receiptHash = Await iweb3.Eth.DeployContract.SendRequestAndWaitForReceiptAsync(abi, bytecode, account.Address, gas, value) | |
' contract address - Get contract | |
Dim tokenContractAddress = receiptHash.ContractAddress | |
Dim tokencontract = iweb3.Eth.GetContract(abi, tokenContractAddress) | |
Dim callfunc = tokencontract.GetFunction("callTest") | |
Dim transactionHash As Nethereum.RPC.Eth.DTOs.TransactionReceipt | |
Dim blockNumber As ULong | |
'call function | |
For x As Integer = 0 To 3 | |
transactionHash = Await callfunc.SendTransactionAndWaitForReceiptAsync(account.Address, gas, value, Nothing, 1) | |
Debug.Print("Transaction included in block number: " & transactionHash.BlockNumber.Value.ToString & ", transaction hash: " & transactionHash.TransactionHash.ToString) | |
' let's try to retrieve the values for the second blocknumber later, just to be sure blockparam works | |
If x = 1 Then | |
blockNumber = transactionHash.BlockNumber.Value | |
End If | |
Next | |
Dim callEvent = tokencontract.GetEvent("raiseMe") | |
Dim filter = callEvent.CreateFilterInput(New Nethereum.RPC.Eth.DTOs.BlockParameter(blockNumber), 'get specified block number | |
Nethereum.RPC.Eth.DTOs.BlockParameter.CreateLatest()) | |
'create my Event DTO class | |
Dim log = Await callEvent.GetAllChanges(Of raiseMeClass)(filter) | |
Debug.Print(log(0).Event.GiveMeValue.ToString) 'will return 2 (starting from 1, so we will get 2) | |
Debug.Print(log(0).Event.GiveMeAddress.ToString) 'will return address | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nethereum v3.0.0rc-1