Skip to content

Commit 1b8a392

Browse files
authored
console: use default APIs when server doesn't have rpc_modules (ethereum#26267)
1 parent 743e404 commit 1b8a392

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

console/console.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
"github.com/ethereum/go-ethereum/internal/jsre"
3535
"github.com/ethereum/go-ethereum/internal/jsre/deps"
3636
"github.com/ethereum/go-ethereum/internal/web3ext"
37+
"github.com/ethereum/go-ethereum/log"
3738
"github.com/ethereum/go-ethereum/rpc"
3839
"github.com/mattn/go-colorable"
3940
"github.com/peterh/liner"
@@ -198,13 +199,22 @@ func (c *Console) initWeb3(bridge *bridge) error {
198199
return err
199200
}
200201

202+
var defaultAPIs = map[string]string{"eth": "1.0", "net": "1.0", "debug": "1.0"}
203+
201204
// initExtensions loads and registers web3.js extensions.
202205
func (c *Console) initExtensions() error {
203-
// Compute aliases from server-provided modules.
206+
const methodNotFound = -32601
204207
apis, err := c.client.SupportedModules()
205208
if err != nil {
206-
return fmt.Errorf("api modules: %v", err)
209+
if rpcErr, ok := err.(rpc.Error); ok && rpcErr.ErrorCode() == methodNotFound {
210+
log.Warn("Server does not support method rpc_modules, using default API list.")
211+
apis = defaultAPIs
212+
} else {
213+
return err
214+
}
207215
}
216+
217+
// Compute aliases from server-provided modules.
208218
aliases := map[string]struct{}{"eth": {}, "personal": {}}
209219
for api := range apis {
210220
if api == "web3" {

0 commit comments

Comments
 (0)