ethclient: support networkID in hex format (#30263)

Some chains’ network IDs use hexadecimal such as Optimism ("0xa" instead
of "10"), so when converting the string to big.Int, we cannot specify
base 10; otherwise, it will encounter errors with hexadecimal network
IDs.
pull/30270/head
Zhihao Lin 3 months ago committed by GitHub
parent dbc1d04f5e
commit e9981bc6f7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      ethclient/ethclient.go

@ -359,7 +359,7 @@ func (ec *Client) NetworkID(ctx context.Context) (*big.Int, error) {
if err := ec.c.CallContext(ctx, &ver, "net_version"); err != nil { if err := ec.c.CallContext(ctx, &ver, "net_version"); err != nil {
return nil, err return nil, err
} }
if _, ok := version.SetString(ver, 10); !ok { if _, ok := version.SetString(ver, 0); !ok {
return nil, fmt.Errorf("invalid net_version result %q", ver) return nil, fmt.Errorf("invalid net_version result %q", ver)
} }
return version, nil return version, nil

Loading…
Cancel
Save