Skip to content

Commit

Permalink
Merge pull request #158 from DanielSchiavini/chain_id_int
Browse files Browse the repository at this point in the history
feat: chain_id as integer
  • Loading branch information
charles-cooper authored Feb 16, 2024
2 parents 9d3c24e + 179cbfb commit 51da344
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions boa/integrations/jupyter/browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,17 @@ def __init__(self, address=None):
self.signer = BrowserSigner(address)
self.set_eoa(self.signer)

def get_chain_id(self):
return _javascript_call(
def get_chain_id(self) -> int:
chain_id = _javascript_call(
"rpc", "eth_chainId", timeout_message=RPC_TIMEOUT_MESSAGE
)
return int.from_bytes(bytes.fromhex(chain_id[2:]), "big")

def set_chain_id(self, chain_id):
def set_chain_id(self, chain_id: int | str):
_javascript_call(
"rpc",
"wallet_switchEthereumChain",
[{"chainId": chain_id}],
[{"chainId": chain_id if isinstance(chain_id, str) else hex(chain_id)}],
timeout_message=RPC_TIMEOUT_MESSAGE,
)
self._reset_fork()
Expand Down

0 comments on commit 51da344

Please sign in to comment.