Created
September 26, 2017 12:35
-
-
Save juanfranblanco/048ba845cc5db4c3d0823b0949b73ab3 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
using Nethereum.Geth; | |
using Nethereum.Hex.HexTypes; | |
using Nethereum.Web3.Accounts.Managed; | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace SimpleTest | |
{ | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var t = Task.Run(() => ShouldBeAbleToDeployAContract()); | |
t.Wait(); | |
Console.ReadKey(); | |
} | |
public static async Task ShouldBeAbleToDeployAContract() | |
{ | |
var senderAddress = "0x12890d2cce102216644c59daE5baed380d84830c"; | |
var password = "password"; | |
var abi = @"[{'constant':false,'inputs':[{'name':'x','type':'uint256'}],'name':'change','outputs':[],'payable':false,'type':'function'},{'constant':false,'inputs':[{'name':'a','type':'uint256'}],'name':'multiply','outputs':[{'name':'d','type':'uint256'}],'payable':false,'type':'function'}]"; | |
var byteCode = | |
"0x60606040526007600055341561001457600080fd5b5b60c0806100236000396000f300606060405263ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166375322e4781146046578063c6888fa114605b575b600080fd5b3415605057600080fd5b60596004356080565b005b3415606557600080fd5b606e6004356089565b60405190815260200160405180910390f35b60008190555b50565b60005481025b9190505600a165627a7a72305820e968f1718f54e45928bdc522341c62736307a6445913275f6cc645b22376550f0029"; | |
var multiplier = 7; | |
//a managed account uses personal_sendTransanction with the given password, this way we don't need to unlock the account for a certain period of time | |
var account = new ManagedAccount(senderAddress, password); | |
//using the specific geth web3 library to allow us manage the mining. | |
var web3 = new Web3Geth(account); | |
// start mining | |
await web3.Miner.Start.SendRequestAsync(6); | |
var transactionHash = | |
await web3.Eth.DeployContract.SendRequestAsync(abi, byteCode, senderAddress, new HexBigInteger(900000)); | |
var receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash); | |
while (receipt == null) | |
{ | |
Thread.Sleep(5000); | |
receipt = await web3.Eth.Transactions.GetTransactionReceipt.SendRequestAsync(transactionHash); | |
} | |
//Contract | |
var con = web3.Eth.GetContract(abi, receipt.ContractAddress); | |
var function = con.GetFunction("multiply"); | |
var res = await function.CallAsync<uint>(10); | |
function = con.GetFunction("change"); | |
var txnHashChange = await function.SendTransactionAsync(senderAddress, 10); //HANGS HERE | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment