2022-02-07 18:37:50 +01:00
|
|
|
import json
|
2022-02-03 15:23:51 +01:00
|
|
|
import ./core, ./response_type
|
|
|
|
|
|
|
|
export response_type
|
|
|
|
|
|
|
|
proc getAccounts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
return core.callPrivateRPC("eth_accounts")
|
|
|
|
|
|
|
|
proc getBlockByNumber*(blockNumber: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
let payload = %* [blockNumber, false]
|
|
|
|
return core.callPrivateRPC("eth_getBlockByNumber", payload)
|
|
|
|
|
2022-02-10 13:10:56 +01:00
|
|
|
proc getNativeChainBalance*(chainId: int, address: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
2022-02-03 15:23:51 +01:00
|
|
|
let payload = %* [address, "latest"]
|
2022-02-17 10:15:37 +01:00
|
|
|
return core.callPrivateRPCWithChainId("eth_getBalance", chainId, payload)
|
2022-02-03 15:23:51 +01:00
|
|
|
|
|
|
|
proc sendTransaction*(transactionData: string, password: string): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
core.sendTransaction(transactionData, password)
|
|
|
|
|
|
|
|
# This is the replacement of the `call` function
|
|
|
|
proc doEthCall*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
core.callPrivateRPC("eth_call", payload)
|
|
|
|
|
|
|
|
proc estimateGas*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
core.callPrivateRPC("eth_estimateGas", payload)
|
|
|
|
|
|
|
|
proc getEthAccounts*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
return core.callPrivateRPC("eth_accounts")
|
|
|
|
|
|
|
|
proc getGasPrice*(payload = %* []): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
return core.callPrivateRPC("eth_gasPrice", payload)
|
2022-02-28 13:30:36 +01:00
|
|
|
|
|
|
|
proc maxPriorityFeePerGas*(): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
let payload = %* []
|
|
|
|
return core.callPrivateRPC("eth_maxPriorityFeePerGas", payload)
|
|
|
|
|
|
|
|
proc feeHistory*(n: int): RpcResponse[JsonNode] {.raises: [Exception].} =
|
|
|
|
let payload = %* [n, "latest", nil]
|
|
|
|
return core.callPrivateRPC("eth_feeHistory", payload)
|