Skip to content

Commit 1c5ef3c

Browse files
committed
add new command devd q eth_chainId
1 parent d5102b4 commit 1c5ef3c

File tree

7 files changed

+43
-24
lines changed

7 files changed

+43
-24
lines changed

README.md

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -60,34 +60,23 @@ devd query erc20 [ERC20 addr] [optional account] [--evm-rpc http://localhost:854
6060

6161
_This command will try to query `totalSupply()` if possible_
6262

63-
#### Get EVM transaction information
63+
#### Some EVM-RPC queries
6464

6565
```bash
6666
devd query eth_getTransactionByHash [0xHash] [--evm-rpc http://localhost:8545]
67-
# devd q tx 0xHash
68-
```
69-
70-
#### Get EVM transaction receipt
7167

72-
```bash
7368
devd query eth_getTransactionReceipt [0xHash] [--evm-rpc http://localhost:8545]
7469
# devd q receipt 0xHash
75-
```
76-
77-
#### Get EVM block by number
7870

79-
```bash
8071
devd query eth_getBlockByNumber [hex or dec block no] [--full] [--evm-rpc http://localhost:8545]
81-
# devd q block 0xF
82-
# devd q block 16 --full
83-
```
84-
85-
#### Trace EVM transaction
72+
# devd q eth_getBlockByNumber 0xF
73+
# devd q eth_getBlockByNumber 16 --full
8674

87-
```bash
8875
devd query debug_traceTransaction [0xHash] [--tracer callTracer] [--evm-rpc http://localhost:8545]
8976
# devd q trace 0xHash
9077
# devd q trace 0xHash --tracer callTracer
78+
79+
devd query eth_chainId [--evm-rpc http://localhost:8545]
9180
```
9281

9382
### Tx tools

cmd/query/debug_traceTransaction.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
flagNoTranslate = "no-translate"
2222
)
2323

24-
func GetQueryTraceTxCommand() *cobra.Command {
24+
func GetQueryEvmRpcDebugTraceTransactionCommand() *cobra.Command {
2525
cmd := &cobra.Command{
2626
Use: "debug_traceTransaction [0xhash]",
2727
Aliases: []string{"trace"},

cmd/query/eth_chainId.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package query
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"github.com/bcdevtools/devd/v3/cmd/flags"
7+
"github.com/bcdevtools/devd/v3/cmd/utils"
8+
"github.com/spf13/cobra"
9+
)
10+
11+
func GetQueryEvmRpcEthChainIdCommand() *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "eth_chainId",
14+
Short: "Query `eth_chainId` from EVM RPC",
15+
Args: cobra.NoArgs,
16+
Run: func(cmd *cobra.Command, args []string) {
17+
ethClient, _ := flags.MustGetEthClient(cmd)
18+
19+
chainId, err := ethClient.ChainID(context.Background())
20+
utils.ExitOnErr(err, "failed to get chain id")
21+
22+
fmt.Println(chainId.String())
23+
},
24+
}
25+
26+
cmd.Flags().String(flags.FlagEvmRpc, "", flags.FlagEvmRpcDesc)
27+
28+
return cmd
29+
}

cmd/query/eth_getBlockByNumber.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const (
2020
flagFull = "full"
2121
)
2222

23-
func GetQueryBlockCommand() *cobra.Command {
23+
func GetQueryEvmRpcEthGetBlockByNumberCommand() *cobra.Command {
2424
cmd := &cobra.Command{
2525
Use: "eth_getBlockByNumber [height dec or 0xHex]",
2626
Short: "Query `eth_getBlockByNumber` from EVM RPC",

cmd/query/eth_getTransactionByHash.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/spf13/cobra"
1515
)
1616

17-
func GetQueryTxCommand() *cobra.Command {
17+
func GetQueryEvmRpcEthGetTransactionByHashCommand() *cobra.Command {
1818
cmd := &cobra.Command{
1919
Use: "eth_getTransactionByHash [0xhash]",
2020
Short: "Query `eth_getTransactionByHash` from EVM RPC",

cmd/query/eth_getTransactionReceipt.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/spf13/cobra"
1515
)
1616

17-
func GetQueryTxReceiptCommand() *cobra.Command {
17+
func GetQueryEvmRpcEthGetTransactionReceiptCommand() *cobra.Command {
1818
cmd := &cobra.Command{
1919
Use: "eth_getTransactionReceipt [0xhash]",
2020
Aliases: []string{"receipt"},

cmd/query/root.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ func Commands() *cobra.Command {
2020

2121
cmd.AddCommand(
2222
GetQueryErc20Command(),
23-
GetQueryTxCommand(),
24-
GetQueryTxReceiptCommand(),
25-
GetQueryBlockCommand(),
26-
GetQueryTraceTxCommand(),
2723
GetQueryBalanceCommand(),
2824
GetQueryTxsInBlockCommand(),
2925
GetQueryTxEventsCommand(),
26+
GetQueryEvmRpcEthGetTransactionByHashCommand(),
27+
GetQueryEvmRpcEthGetTransactionReceiptCommand(),
28+
GetQueryEvmRpcEthGetBlockByNumberCommand(),
29+
GetQueryEvmRpcEthChainIdCommand(),
30+
GetQueryEvmRpcDebugTraceTransactionCommand(),
3031
// fake command for deprecated alias
3132
GetDeprecatedAliasBlockAsCommand(),
3233
GetDeprecatedAliasTxAsCommand(),

0 commit comments

Comments
 (0)