Skip to content

Commit fe7679e

Browse files
committed
add hint setting EVM Json-RPC url
1 parent cdb69ea commit fe7679e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

cmd/query/evm.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package query
22

33
import (
44
"bytes"
5+
"context"
56
"encoding/hex"
67
"fmt"
78
"github.com/bcdevtools/devd/v2/cmd/types"
@@ -117,6 +118,14 @@ func mustGetEthClient(cmd *cobra.Command, fallbackDeprecatedFlagHost bool) (*eth
117118
ethClient8545, err := ethclient.Dial(rpc)
118119
utils.ExitOnErr(err, "failed to connect to EVM Json-RPC")
119120

121+
// pre-flight check to ensure the connection is working
122+
_, err = ethClient8545.BlockNumber(context.Background())
123+
if err != nil && strings.Contains(err.Error(), "connection refused") {
124+
utils.PrintlnStdErr("ERR: failed to connect to EVM Json-RPC, please check the connection and try again.")
125+
utils.PrintfStdErr("ERR: if you are using a custom EVM Json-RPC, please provide it via flag '--%s <your_custom>' or setting environment variable 'export %s=<your_custom>'.\n", flagRpc, constants.ENV_EVM_RPC)
126+
os.Exit(1)
127+
}
128+
120129
return ethClient8545, rpc
121130
}
122131

constants/varcons.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ package constants
44

55
//goland:noinspection GoSnakeCaseUsage
66
var (
7-
VERSION = "2.0.2"
7+
VERSION = "2.0.3"
88
)

0 commit comments

Comments
 (0)