deploy: 3101e545b6e78ebcc60cb1b86b8c47614e4ffbe9

This commit is contained in:
staheri14 2021-02-04 20:24:28 +00:00
parent 9d86a8b2e1
commit 209e023445
5 changed files with 129 additions and 69 deletions

View File

@ -1 +1 @@
1612467000
1612469425

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,17 @@
import web3, chronos, options, stint
proc deployContract*(web3: Web3, code: string, gasPrice = 0): Future[ReceiptObject] {.async.} =
proc deployContract*(web3: Web3, code: string, gasPrice = 0, contractInput = ""): Future[ReceiptObject] {.async.} =
# the contract input is the encoded version of contract constructor's input
# use nim-web3/encoding.nim module to find the appropriate encoding procedure for different argument types
# e.g., consider the following contract constructor in solidity
# constructor(uint256 x, uint256 y)
#
# the contractInput can be calculated as follows
# let
# x = 1.u256
# y = 5.u256
# contractInput = encode(x).data & encode(y).data
# Note that the order of encoded inputs should match the order of the constructor inputs
let provider = web3.provider
let accounts = await provider.eth_accounts()
@ -9,7 +20,7 @@ proc deployContract*(web3: Web3, code: string, gasPrice = 0): Future[ReceiptObje
code = "0x" & code
var tr: EthSend
tr.source = web3.defaultAccount
tr.data = code
tr.data = code & contractInput
tr.gas = Quantity(3000000000000).some
if gasPrice != 0:
tr.gasPrice = some(gasPrice)

File diff suppressed because one or more lines are too long