Add Signer.getChainId()
This commit is contained in:
parent
7e32f5ee51
commit
4acc6ef45c
|
@ -29,3 +29,6 @@ method getTransactionCount*(provider: Provider,
|
|||
method estimateGas*(provider: Provider,
|
||||
transaction: Transaction): Future[UInt256] {.base.} =
|
||||
doAssert false, "not implemented"
|
||||
|
||||
method getChainId*(provider: Provider): Future[UInt256] {.base.} =
|
||||
doAssert false, "not implemented"
|
||||
|
|
|
@ -80,6 +80,13 @@ method estimateGas*(provider: JsonRpcProvider,
|
|||
let client = await provider.client
|
||||
return await client.eth_estimateGas(transaction)
|
||||
|
||||
method getChainId*(provider: JsonRpcProvider): Future[UInt256] {.async.} =
|
||||
let client = await provider.client
|
||||
try:
|
||||
return await client.eth_chainId()
|
||||
except CatchableError:
|
||||
return parse(await client.net_version(), UInt256)
|
||||
|
||||
# Signer
|
||||
|
||||
method provider*(signer: JsonRpcSigner): Provider =
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
proc net_version(): string
|
||||
proc eth_accounts: seq[Address]
|
||||
proc eth_blockNumber: UInt256
|
||||
proc eth_call(transaction: Transaction): seq[byte]
|
||||
proc eth_gasPrice(): UInt256
|
||||
proc eth_getTransactionCount(address: Address, blockTag: BlockTag): UInt256
|
||||
proc eth_estimateGas(transaction: Transaction): UInt256
|
||||
proc eth_chainId(): UInt256
|
||||
|
|
|
@ -25,3 +25,6 @@ method estimateGas*(signer: Signer,
|
|||
var transaction = transaction
|
||||
transaction.sender = some(await signer.getAddress)
|
||||
return await signer.provider.estimateGas(transaction)
|
||||
|
||||
method getChainId*(signer: Signer): Future[UInt256] {.base.} =
|
||||
signer.provider.getChainId()
|
||||
|
|
|
@ -33,3 +33,8 @@ suite "JsonRpcSigner":
|
|||
let signer = provider.getSigner()
|
||||
let estimate = await signer.estimateGas(Transaction.example)
|
||||
check estimate > 0.u256
|
||||
|
||||
test "can retrieve chain id":
|
||||
let signer = provider.getSigner()
|
||||
let chainId = await signer.getChainId()
|
||||
check chainId == 31337.u256 # hardhat chain id
|
||||
|
|
Loading…
Reference in New Issue