2

I am trying to deploy smart contract in Ethereum network using Nethereum (c#) library.

var abi = "[ABI...]";
var bytecode = "0x00...";

var gas = await web3.Eth.DeployContract.EstimateGasAsync(abi, bytecode, publicKey,  "Zuk04");
await web3.Eth.DeployContract.SendRequestAsync(abi, bytecode, publicKey, gas, new HexBigInteger("0"), "Zuk01");

How can I get notification and contract address when it will be deployed ?

I know that SendRequestAndWaitForReceiptAsync() function exists, but in real scenario this approach may take long period, so I need something like an event (contract deployment event).

user19291301
  • 127
  • 8

2 Answers2

0
  const result = await new web3.eth.Contract(abi)
    .deploy({
      data: evm.bytecode.object,
      arguments: ["This is a real foo contract, not smart at all."],
    })
    .send({ gas: "1000000", from: accounts[0] });

  console.log("Contract deployed to", result.options.address);

This is a javascript example (I am not familiar with C#), but as you can see, the variable you declare for deploying also contains the address of the contract once it is deployed. In your case, you may have a similar situation in your "gas" object.

  • I can make something like that in c#, but deploying contract may take some time (1-5 min) so I just want to tell blockhain that I need this contract to be deployed (I am not waiting deployment process) and when it will be deployed just emit an event. – user19291301 Nov 30 '22 at 06:58
  • This is exactly what happens when you use async/await. The function works in the background and you get the response as soon as it is ready. – Davide Di Francesco Nov 30 '22 at 09:41
  • I want to deploy contract when HTTP request will be received by API. If I will use this approach, request sender has to wait during this period and probably there will be http timeout exception. So I want to response sender that Contract will be deployed and when it will be deployed I want to get event from ethereum network and next I will notify request sender as well. await keyword is not problem solver here, because response will not be sent untill deploy process finish. – user19291301 Nov 30 '22 at 10:01
0

For your use case there is a pretty simple solution. You need to handle contract deployment out of the http's request scope.

You could create some kind of queue (it could be just table in database) and then your request will write entry to this table. Then you will need some hosted service or different process just to fetch entries and to proceed with contract deployment.

This is almost implementation of OutboxPattern. The only tricky part is how to notify user, it will be depending on your process.

If you want to have real time notification you will need to use websockets or long polling (SignalR lib is great with that).

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Kamil Kiełbasa
  • 130
  • 1
  • 7