Reputation: 143
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).
Upvotes: 2
Views: 607
Reputation: 150
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).
Upvotes: 0
Reputation: 63
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.
Upvotes: 0