Get the network version (a.k.a. chainId)
()
| 532 | |
| 533 | // Get the network version (a.k.a. chainId) |
| 534 | func (client *EthereumClient) NetVersion() (int64, error) { |
| 535 | |
| 536 | reqBody := JSONRPCRequest{ |
| 537 | JSONRPC: "2.0", |
| 538 | ID: 1, |
| 539 | Method: "net_version", |
| 540 | Params: []interface{}{}, |
| 541 | } |
| 542 | |
| 543 | body, err := client.issueRequest(&reqBody) |
| 544 | if err != nil { |
| 545 | return 0, err |
| 546 | } |
| 547 | |
| 548 | var clientResp BlockNumberResponse |
| 549 | err = json.Unmarshal(body, &clientResp) |
| 550 | if err != nil { |
| 551 | return 0, err |
| 552 | } |
| 553 | version, err := strconv.ParseInt(clientResp.Result, 10, 64) |
| 554 | // if err != nil { |
| 555 | // return 0, err |
| 556 | // } |
| 557 | |
| 558 | return int64(version), nil |
| 559 | } |
| 560 | |
| 561 | // Use this to make calls to a contract |
| 562 | type Call struct { |
no test coverage detected