1import Web3 from 'web3';
2import { toHex } from 'web3-utils';
3import { FakeSignableTx, FakeSignResult } from './txn';
5export class MetamaskWallet {
8 constructor(address: string) {
9 this.address = address;
13// Cheat a bit and pretend to sign transaction
14// Sign it actually when sending
15export const metamaskSignTransaction = async (
20 return FakeSignResult(txn, metamaskSendTransaction);
23const metamaskSendTransaction = async (txn: FakeSignableTx, web3: Web3) => {
24 const metamaskFormattedTxn = {
26 gasLimit: txn.gasLimit,
27 gasPrice: txn.gasPrice,
30 from: toHex(txn.from),
34 if (window.ethereum) {
35 //NOTE see also #596, #630, #646
36 // no idea what's going on, we should figure it out,
37 // but we apply this bandaid to hopefully stop the bleeding.
38 // at least it also helps with the NOTE of the other branch.
39 txHash = await window.ethereum.request({
40 method: 'eth_sendTransaction',
41 params: [metamaskFormattedTxn],
45 //NOTE since this gives us a receipt instead of just the hash of the
46 // signed tx, it makes us wait for confirmation outside of our own
47 // waitForTransactionConfirm. because of this the progress bar loses
48 // its progressiveness for metamask users.
49 let receipt = await await web3.eth.sendTransaction(metamaskFormattedTxn);
50 txHash = receipt.transactionHash;
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list