diff --git a/ethers/contract.nim b/ethers/contract.nim index 6bf0ce6..799a994 100644 --- a/ethers/contract.nim +++ b/ethers/contract.nim @@ -56,16 +56,20 @@ proc decodeResponse(T: type, bytes: seq[byte]): T = raiseContractError "unable to decode return value as " & $T return decoded -proc call(contract: Contract, function: string, parameters: tuple) {.async.} = +proc call(contract: Contract, + function: string, + parameters: tuple, + blockTag = BlockTag.latest) {.async.} = let transaction = createTransaction(contract, function, parameters) - discard await contract.provider.call(transaction) + discard await contract.provider.call(transaction, blockTag) proc call(contract: Contract, function: string, parameters: tuple, - ReturnType: type): Future[ReturnType] {.async.} = + ReturnType: type, + blockTag = BlockTag.latest): Future[ReturnType] {.async.} = let transaction = createTransaction(contract, function, parameters) - let response = await contract.provider.call(transaction) + let response = await contract.provider.call(transaction, blockTag) return decodeResponse(ReturnType, response) proc send(contract: Contract, function: string, parameters: tuple) {.async.} = diff --git a/ethers/provider.nim b/ethers/provider.nim index 2a8badf..1aa21ce 100644 --- a/ethers/provider.nim +++ b/ethers/provider.nim @@ -30,7 +30,9 @@ method getBlockNumber*(provider: Provider): Future[UInt256] {.base.} = method getBlock*(provider: Provider, tag: BlockTag): Future[?Block] {.base.} = doAssert false, "not implemented" -method call*(provider: Provider, tx: Transaction): Future[seq[byte]] {.base.} = +method call*(provider: Provider, + tx: Transaction, + blockTag = BlockTag.latest): Future[seq[byte]] {.base.} = doAssert false, "not implemented" method getGasPrice*(provider: Provider): Future[UInt256] {.base.} = diff --git a/ethers/providers/jsonrpc.nim b/ethers/providers/jsonrpc.nim index b9e26ab..f33df34 100644 --- a/ethers/providers/jsonrpc.nim +++ b/ethers/providers/jsonrpc.nim @@ -77,9 +77,10 @@ method getBlock*(provider: JsonRpcProvider, return await client.eth_getBlockByNumber(tag, false) method call*(provider: JsonRpcProvider, - tx: Transaction): Future[seq[byte]] {.async.} = + tx: Transaction, + blockTag = BlockTag.latest): Future[seq[byte]] {.async.} = let client = await provider.client - return await client.eth_call(tx) + return await client.eth_call(tx, blockTag) method getGasPrice*(provider: JsonRpcProvider): Future[UInt256] {.async.} = let client = await provider.client diff --git a/ethers/providers/jsonrpc/signatures.nim b/ethers/providers/jsonrpc/signatures.nim index 7f50b80..7ce1af7 100644 --- a/ethers/providers/jsonrpc/signatures.nim +++ b/ethers/providers/jsonrpc/signatures.nim @@ -1,7 +1,7 @@ proc net_version(): string proc eth_accounts: seq[Address] proc eth_blockNumber: UInt256 -proc eth_call(transaction: Transaction): seq[byte] +proc eth_call(transaction: Transaction, blockTag: BlockTag): seq[byte] proc eth_gasPrice(): UInt256 proc eth_getBlockByNumber(blockTag: BlockTag, includeTransactions: bool): ?Block proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256