Skip to content

Instantly share code, notes, and snippets.

@Enigmatic331
Created January 14, 2019 04:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Enigmatic331/002d06c895da6332d520499981cd36b5 to your computer and use it in GitHub Desktop.
Save Enigmatic331/002d06c895da6332d520499981cd36b5 to your computer and use it in GitHub Desktop.
Quick test on how a smart contract raw deployment looks like
Private Async Sub testContract()
Dim SHK As New Sha3Keccack
' from account - account we are transferring from
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"":true,""inputs"":[],""name"":""storeMe"",""outputs"":[{""name"":"""",""type"":""uint256""}],""payable"":false,""stateMutability"":""view"",""type"":""function""},{""constant"":true,""inputs"":[],""name"":""getMe"",""outputs"":[{""name"":"""",""type"":""uint256""}],""payable"":false,""stateMutability"":""view"",""type"":""function""},{""constant"":false,""inputs"":[{""name"":""_setMe"",""type"":""uint256""}],""name"":""setMe"",""outputs"":[],""payable"":false,""stateMutability"":""nonpayable"",""type"":""function""}]"
Dim bytecode = "0x608060405234801561001057600080fd5b5060e18061001f6000396000f30060806040526004361060525763ffffffff7c0100000000000000000000000000000000000000000000000000000000600035041663ad081b7e81146057578063c11e1ff314607b578063d88cdbd614608d575b600080fd5b348015606257600080fd5b50606960a4565b60408051918252519081900360200190f35b348015608657600080fd5b50606960aa565b348015609857600080fd5b5060a260043560b0565b005b60005481565b60005490565b6000555600a165627a7a723058207ef94d70d3ddcfe592bbf9103099e7c8ac4f23a0d168f50b5cdde100c1f7d1340029"
Dim iweb3 = New Web3(account, "https://ropsten.infura.io")
'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 txCount = Await iweb3.Eth.Transactions.GetTransactionCount.SendRequestAsync(privateKey.GetPublicAddress)
Dim encodedString = iweb3.OfflineTransactionSigner.SignTransaction(privateKey.GetPrivateKey, "", value, txCount.Value, New HexBigInteger(8000000000), gas, bytecode)
Dim txID = Await iweb3.Eth.Transactions.SendRawTransaction.SendRequestAsync("0x" & encodedString)
Dim receipt = Await iweb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txID)
'if receipt is received, transaction should be sent
While receipt Is Nothing
Thread.Sleep(5000)
receipt = Await iweb3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(txID)
End While
MsgBox("Transaction included in block number: " & receipt.BlockNumber.Value.ToString & ", transaction hash: " & receipt.TransactionHash.ToString)
Dim contractAddress = receipt.ContractAddress
Dim contractObj = iweb3.Eth.GetContract(abi, contractAddress)
Dim setMe = contractObj.GetFunction("setMe")
Dim transactionHash = Await setMe.SendTransactionAndWaitForReceiptAsync(account.Address, gas, value, , 42)
Dim getMe = contractObj.GetFunction("getMe")
Dim getMeValue = Await getMe.CallAsync(Of Integer)
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment