@@ -18,8 +18,12 @@ export const metamaskSignTransaction = async (txn: EIP1559Transaction) => {
1818};
1919
2020const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
21+ /**
22+ * Depending which version of Metamask is installed, there are different
23+ * approaches to get the `from` address.
24+ */
2125 let from = null;
22− if(window.ethereum) {
26+ if (window.ethereum) {
2327 from = window.ethereum.selectedAddress;
2428 if (!from) {
2529 const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
@@ -32,6 +36,10 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
3236 from = accounts[0] ?? null;
3337 }
3438
39+ if (!from) {
40+ throw new Error('No accounts connected');
41+ }
42+
3543 const { data, to, value, maxPriorityFeePerGas, maxFeePerGas } = txn.toJSON();
3644 if (!(data && to && value && maxPriorityFeePerGas && maxFeePerGas && from)) {
3745 throw new Error('Unable to send Metamask TX, something is missing');