@@ -1,5 +1,5 @@
1import { Common, Chain, Hardfork } from '@ethereumjs/common';
1import { Common, Chain, Hardfork } from '@ethereumjs/common';
2−import { JsonTx, Transaction, FeeMarketEIP1559Transaction as EIP1559Transaction, TxOptions, TxData, FeeMarketEIP1559TxData as EIP1559TxData } from '@ethereumjs/tx';
2+import { Transaction, FeeMarketEIP1559Transaction as EIP1559Transaction, TxOptions, TxData, FeeMarketEIP1559TxData as EIP1559TxData } from '@ethereumjs/tx';
3import { ITxData } from '@walletconnect/types';
3import { ITxData } from '@walletconnect/types';
4import { toHex, toWei } from 'web3-utils';
4import { toHex, toWei } from 'web3-utils';
5import retry from 'async-retry';
5import retry from 'async-retry';
@@ -20,21 +20,9 @@ const RETRY_OPTIONS = {
20 randomize: false,
20 randomize: false,
23−type SignableTx = (Transaction | EIP1559Transaction) & {
26− gasPrice?: string; // TODO: is this still needed?
27− gasLimit: string; // TODO: is this still needed?
31−// catch-all type: Metamask passes an obj shaped like ITxData, WC passes JsonTx + from
32−export type FakeSignableTx =
23+export type FakeSignableTx = EIP1559Transaction;
34− | (JsonTx & { from: string; to: string; gas: string })
37−type TxSender = (txn: FakeSignableTx, web3: Web3) => Promise<string>; // Metamask requires Web3 (txhash)
25+type TxSender = (txn: FakeSignableTx, web3: Web3) => Promise<string>;
39export type FakeSignedTx = {
27export type FakeSignedTx = {
40 txn: FakeSignableTx;
28 txn: FakeSignableTx;
@@ -57,7 +45,7 @@ interface signTransactionProps {
57 walletType: symbol;
45 walletType: symbol;
58 walletHdPath: string; // TODO: is this still needed?
46 walletHdPath: string; // TODO: is this still needed?
59 networkType: symbol;
47 networkType: symbol;
60− txn: Transaction | EIP1559Transaction;
48+ txn: { data: string, to: string, value: number }
61 nonce: number | string;
49 nonce: number | string;
62 chainId: number | string;
50 chainId: number | string;
63 gasPriceData: GasPriceData;
51 gasPriceData: GasPriceData;
@@ -74,7 +62,6 @@ const _web3 = () => {
74const estimateGasLimit = async (utx: TransactionConfig) => {
62const estimateGasLimit = async (utx: TransactionConfig) => {
75 const web3 = _web3();
63 const web3 = _web3();
76 const estimate = await web3.eth.estimateGas(utx);
64 const estimate = await web3.eth.estimateGas(utx);
77− console.log(estimate);
78 return web3.utils.toBN(estimate).muln(120).divn(100); // 20% cushion
65 return web3.utils.toBN(estimate).muln(120).divn(100); // 20% cushion
@@ -89,7 +76,7 @@ const signTransaction = async ({
89 walletType,
76 walletType,
90 walletHdPath, // TODO
77 walletHdPath, // TODO
91 networkType,
78 networkType,
92− txn,
79+ txn, // output of transactionBuilder in useEthereumTransaction
93 nonce, // number
80 nonce, // number
94 chainId, // number
81 chainId, // number
95 gasPriceData, // GasPriceData
82 gasPriceData, // GasPriceData
@@ -97,7 +84,6 @@ const signTransaction = async ({
97 txnSigner, // optionally inject a transaction signing function,
84 txnSigner, // optionally inject a transaction signing function,
98 txnSender, // and a sending function, for wallets that need these passed in.
85 txnSender, // and a sending function, for wallets that need these passed in.
99}: signTransactionProps) => {
86}: signTransactionProps) => {
100− console.log('txn', txn);
101 const from = wallet.address;
87 const from = wallet.address;
102 const estimate = await estimateGasLimit({...txn, from });
88 const estimate = await estimateGasLimit({...txn, from });
103 const maxFeePerGas = await getMaxFeePerGas();
89 const maxFeePerGas = await getMaxFeePerGas();
@@ -112,8 +98,6 @@ const signTransaction = async ({
112 chainId: toHex(chainId),
98 chainId: toHex(chainId),
113 type: toHex(EIP1559_TRANSACTION_TYPE),
99 type: toHex(EIP1559_TRANSACTION_TYPE),
116− const utx: SignableTx = Object.assign(txn, txParams);
118 // TODO: Ropsten will sunset Q4 2022, need to replace w/ support for Goerli
102 // TODO: Ropsten will sunset Q4 2022, need to replace w/ support for Goerli
119 const chain =
103 const chain =
@@ -130,7 +114,7 @@ const signTransaction = async ({
130 let stx = EIP1559Transaction.fromTxData(txParams, txConfig)
114 let stx = EIP1559Transaction.fromTxData(txParams, txConfig)
132 if (walletType === WALLET_TYPES.METAMASK) {
116 if (walletType === WALLET_TYPES.METAMASK) {
133− return metamaskSignTransaction(utx);
117+ return metamaskSignTransaction(stx);
134 } else if (walletType === WALLET_TYPES.WALLET_CONNECT) {
118 } else if (walletType === WALLET_TYPES.WALLET_CONNECT) {
135 if (!(txnSender && txnSigner)) {
119 if (!(txnSender && txnSigner)) {
136 throw Error('WalletConnect TX signer unavailable');
120 throw Error('WalletConnect TX signer unavailable');
@@ -152,12 +136,11 @@ const signTransaction = async ({
153const sendSignedTransaction = (
137const sendSignedTransaction = (
154 web3: Web3,
138 web3: Web3,
155− // TODO: do we still need legacy TX type? elsewhere too
156− stx: Transaction | EIP1559Transaction | FakeSignedTx,
139+ stx: EIP1559Transaction | FakeSignedTx,
157 doubtNonceError: boolean
140 doubtNonceError: boolean
158): Promise<string> => {
141): Promise<string> => {
159 // if we couldn't sign it, we depend on the given sender function
142 // if we couldn't sign it, we depend on the given sender function
160− if (!(stx instanceof Transaction || stx instanceof EIP1559Transaction)) { // TODO
143+ if (!(stx instanceof EIP1559Transaction)) { // TODO
161 if (doubtNonceError) {
144 if (doubtNonceError) {
162 console.log('why doubting nonce error? tank unavailable without rawtx.');
145 console.log('why doubting nonce error? tank unavailable without rawtx.');
@@ -221,7 +204,7 @@ const waitForTransactionConfirm = (web3: Web3, txHash: string) => {
221// returns a Promise that resolves when all stxs have been sent & confirmed
204// returns a Promise that resolves when all stxs have been sent & confirmed
222const sendAndAwaitAll = (
205const sendAndAwaitAll = (
223 web3: Web3,
206 web3: Web3,
224− stxs: Transaction[] | EIP1559Transaction[] | FakeSignedTx[],
207+ stxs: EIP1559Transaction[] | FakeSignedTx[],
225 doubtNonceError: boolean
208 doubtNonceError: boolean
227 return Promise.all(
210 return Promise.all(
@@ -234,13 +217,12 @@ const sendAndAwaitAll = (
235const sendAndAwaitAllSerial = (
218const sendAndAwaitAllSerial = (
236 web3: Web3,
219 web3: Web3,
237− stxs: Array<Transaction> | Array<EIP1559Transaction> | Array<FakeSignedTx>,
220+ stxs: EIP1559Transaction[] | FakeSignedTx[],
238 doubtNonceError: boolean
221 doubtNonceError: boolean
240− // tsc complains that stxs.reduce() is not callable
223+ //@ts-expect-error tsc complains that stxs.reduce() is not callable
242 return stxs.reduce(
224 return stxs.reduce(
243− (promise: Promise<TransactionReceipt[]>, stx: Transaction | FakeSignedTx) =>
225+ (promise: Promise<TransactionReceipt[]>, stx: EIP1559Transaction | FakeSignedTx) =>
244 promise.then(async (receipts = []) => {
226 promise.then(async (receipts = []) => {
245 const txHash = await sendSignedTransaction(web3, stx, doubtNonceError);
227 const txHash = await sendSignedTransaction(web3, stx, doubtNonceError);
246 return [...receipts, await waitForTransactionConfirm(web3, txHash)];
228 return [...receipts, await waitForTransactionConfirm(web3, txHash)];
@@ -251,7 +233,7 @@ const sendAndAwaitAllSerial = (
252const sendTransactionsAndAwaitConfirm = async (
234const sendTransactionsAndAwaitConfirm = async (
253 web3: Web3,
235 web3: Web3,
254− signedTxs: Array<Transaction> | Array<EIP1559Transaction> | Array<FakeSignedTx>,
236+ signedTxs: EIP1559Transaction[] | FakeSignedTx[],
255 usedTank: boolean
237 usedTank: boolean
257 Promise.all(signedTxs.map(tx => sendSignedTransaction(web3, tx, usedTank)));
239 Promise.all(signedTxs.map(tx => sendSignedTransaction(web3, tx, usedTank)));