@@ -18,8 +18,12 @@ export const metamaskSignTransaction = async (txn: EIP1559Transaction) => {
20const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
20const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
22+ * Depending which version of Metamask is installed, there are different
23+ * approaches to get the `from` address.
21 let from = null;
25 let from = null;
22− if(window.ethereum) {
26+ if (window.ethereum) {
23 from = window.ethereum.selectedAddress;
27 from = window.ethereum.selectedAddress;
24 if (!from) {
28 if (!from) {
25 const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
29 const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
@@ -32,6 +36,10 @@ const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
32 from = accounts[0] ?? null;
36 from = accounts[0] ?? null;
40+ throw new Error('No accounts connected');
35 const { data, to, value, maxPriorityFeePerGas, maxFeePerGas } = txn.toJSON();
43 const { data, to, value, maxPriorityFeePerGas, maxFeePerGas } = txn.toJSON();
36 if (!(data && to && value && maxPriorityFeePerGas && maxFeePerGas && from)) {
44 if (!(data && to && value && maxPriorityFeePerGas && maxFeePerGas && from)) {
37 throw new Error('Unable to send Metamask TX, something is missing');
45 throw new Error('Unable to send Metamask TX, something is missing');