diff --git a/boa/integrations/jupyter/browser.py b/boa/integrations/jupyter/browser.py index 021e5682..15d53363 100644 --- a/boa/integrations/jupyter/browser.py +++ b/boa/integrations/jupyter/browser.py @@ -153,8 +153,31 @@ class BrowserEnv(NetworkEnv): def __init__(self, address=None, **kwargs): super().__init__(self._rpc, **kwargs) - self.signer = BrowserSigner(address, self._rpc) - self.set_eoa(self.signer) + self._given_address = address + + @property + def signer(self): + """ + Create a BrowserSigner instance. This needs to be recreated for every + call as the wallet address may change. + """ + return BrowserSigner(self._given_address, self._rpc) + + @property + def eoa(self): + """ + Retrieves the current eoa to sign transactions. This needs to be recreated + for every call as the wallet address may change. + """ + signer = self.signer + self._accounts[signer.address] = signer + return signer.address + + @eoa.setter + def eoa(self, address): + err = "Setting an eoa is not supported for BrowserEnv, " + # but, it's called from the env constructors, so check the expected values + assert address is None or self._aliases[address.canonical_address] == "eoa", err def set_chain_id(self, chain_id: int | str): self._rpc.fetch( diff --git a/boa/integrations/jupyter/jupyter.js b/boa/integrations/jupyter/jupyter.js index cd8f3726..3645ce62 100644 --- a/boa/integrations/jupyter/jupyter.js +++ b/boa/integrations/jupyter/jupyter.js @@ -42,14 +42,6 @@ return response.text(); } - const loadSigner = async (address) => { - const accounts = await rpc('eth_requestAccounts'); - return accounts.includes(address) ? address : accounts[0]; - }; - - /** Sign a transaction via ethers */ - const sendTransaction = async transaction => ({"hash": await rpc('eth_sendTransaction', [transaction])}); - /** Wait until the transaction is mined */ const waitForTransactionReceipt = async (tx_hash, timeout, poll_latency) => { while (true) { @@ -81,8 +73,8 @@ const handleCallback = func => async (token, ...args) => { if (!colab) { // Check backend and whether cell was executed. In Colab, eval_js() doesn't replay. - const response = await fetch(`${base}/titanoboa_jupyterlab/callback/${token}`); - if (response.status === 404 && response.headers.get('Content-Type') === 'application/json') { + const response = await fetch(`${config.base}/titanoboa_jupyterlab/callback/${token}`); + if (response.status === 404 && response.headers.get('Content-Type')?.startsWith('application/json')) { return; // the cell has already been executed } if (!response.ok) { @@ -108,8 +100,6 @@ // expose functions to window, so they can be called from the BrowserSigner window._titanoboa = { - loadSigner: handleCallback(loadSigner), - sendTransaction: handleCallback(sendTransaction), waitForTransactionReceipt: handleCallback(waitForTransactionReceipt), rpc: handleCallback(rpc), multiRpc: handleCallback(multiRpc),