-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handling inputs to a smart contract constructor #33
Comments
Original issue by @staheri14. This is also an issue for SWAP accounting that also requires a constructor: waku-org/nwaku#323 @zah or someone else do you have any ideas for how to do this within nim-web3 library? Would be very useful. Also see previous discussion in Nimbus discord. |
A solution for this issue is implemented in this PR waku-org/nwaku#359 (in nim-waku repo), please see https://github.com/status-im/nim-waku/blob/master/tests/v2/test_utils.nim |
Yes, contract dsl now supports constructors, but web3-send api is still missing for that. Here's an example of how one could implement it: import web3, chronos
proc deployContractAux(web3: Web3, data: seq[byte], gasPrice = 0): Future[ReceiptObject] {.async.} =
var tr: EthSend
tr.`from` = web3.defaultAccount
tr.data = data
tr.gas = Quantity(30000000).some
if gasPrice != 0:
tr.gasPrice = some(gasPrice.Quantity)
let r = await web3.send(tr)
return await web3.getMinedTransactionReceipt(r)
proc send*[T](d: ContractDeployment[T, Web3]): Future[Sender[T]] {.async.} =
let receipt = await d.sender.deployContractAux(d.data)
result.sender = typeof(result.sender)(web3: d.sender, contractAddress: receipt.contractAddress.get)
let contractCode: seq[byte] = ... # Load contract code
contract TestContract:
proc constructorNameDoesNotMatter(arg1, arg2: string) {.constructor.}
let web3 = waitFor newWeb3("ws://127.0.0.1:8545/")
let testContract: Sender[TestContract] = waitFor web3.deployContract(TestContract, contractCode, "arg1 value", "arg2 value").send() |
Update: import web3, chronos
let contractCode: seq[byte] = ... # Load contract code
contract TestContract:
proc constructorNameDoesNotMatter(arg1, arg2: string) {.constructor.}
let web3 = waitFor newWeb3("ws://127.0.0.1:8545/")
let testContract: Sender[TestContract] = waitFor web3.deployContract(TestContract, contractCode, "arg1 value", "arg2 value") |
Duplicate of waku-org/nwaku#323
Problem
The problem is about how to deploy a smart contract with its constructor's inputs using nim-web3.
Some thoughts:
The
EthSend
has adata
field which embodies the compiled code of the contract, probably the constructor's parameters should be passed/encoded as part of thedata
field, like<smartcontract code><parameters of constructor>
but couldn't find the encoding procedure in this library.The text was updated successfully, but these errors were encountered: