@@ -18,13 +18,30 @@ 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.
26+ if (window.ethereum) {
27+ from = window.ethereum.selectedAddress;
29+ const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' });
30+ from = accounts[0] ?? null;
32+ } else if (window.web3) {
33+ from = window.web3?.eth?.defaultAccount ?? null;
21− const accounts = await web3.eth.getAccounts();
35+ const accounts = await web3.eth.getAccounts();
22− if(accounts.length === 0) {
36+ from = accounts[0] ?? null;
23 throw new Error('No accounts connected');
40 throw new Error('No accounts connected');
25− const from = accounts[0];
42+
26 const { data, to, value, maxPriorityFeePerGas, maxFeePerGas } = txn.toJSON();
43 const { data, to, value, maxPriorityFeePerGas, maxFeePerGas } = txn.toJSON();
27− if (!(data && to && value && maxPriorityFeePerGas && maxFeePerGas && from)) { // TODO
44+ if (!(data && to && value && maxPriorityFeePerGas && maxFeePerGas && from)) {
28 throw new Error('Unable to send Metamask TX, something is missing');
45 throw new Error('Unable to send Metamask TX, something is missing');