-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8c52163
commit 3a20446
Showing
18 changed files
with
248 additions
and
1,434 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,44 +1,51 @@ | ||
import { providers } from 'ethers'; | ||
import { BrowserProvider } from 'ethers'; | ||
|
||
const { ethereum } = window; | ||
|
||
let activeAccount = null; | ||
|
||
export async function connect(){ | ||
export async function connect() { | ||
const accounts = await ethereum.request({ method: 'eth_requestAccounts' }); | ||
activeAccount = accounts[0]; | ||
console.log("connected", activeAccount) | ||
console.log('connected', activeAccount); | ||
} | ||
|
||
|
||
export async function switchNetwork(chainId){ | ||
export async function switchNetwork(chainId) { | ||
await ethereum.request({ | ||
method: 'wallet_switchEthereumChain', | ||
params: [{ chainId}], | ||
params: [{ chainId }], | ||
}); | ||
|
||
console.log("network switched.") | ||
console.log('network switched.'); | ||
} | ||
|
||
|
||
export async function signEvmTx(evmTransaction){ | ||
let provider = new providers.Web3Provider(ethereum); | ||
let signer = provider.getSigner(); | ||
export async function signEvmTx(evmTransaction) { | ||
const provider = new BrowserProvider(ethereum); | ||
const signer = await provider.getSigner(); | ||
|
||
let tx = {}; | ||
if (!!evmTransaction.from) tx = { ...tx, from: evmTransaction.from }; | ||
if (!!evmTransaction.txTo) tx = { ...tx, to: evmTransaction.txTo }; | ||
if (!!evmTransaction.txData) tx = { ...tx, data: evmTransaction.txData }; | ||
if (!!evmTransaction.value) tx = { ...tx, value: evmTransaction.value }; | ||
if (!!evmTransaction.gasLimit) tx = { ...tx, gasLimit: evmTransaction.gasLimit }; | ||
if (!!evmTransaction.gasPrice) tx = { ...tx, gasPrice: evmTransaction.gasPrice }; | ||
if (!!evmTransaction.nonce) tx = { ...tx, nonce: evmTransaction.nonce }; | ||
if (!!evmTransaction.from) { | ||
tx = { ...tx, from: evmTransaction.from }; | ||
} | ||
if (!!evmTransaction.txTo) { | ||
tx = { ...tx, to: evmTransaction.txTo }; | ||
} | ||
if (!!evmTransaction.txData) { | ||
tx = { ...tx, data: evmTransaction.txData }; | ||
} | ||
if (!!evmTransaction.value) { | ||
tx = { ...tx, value: evmTransaction.value }; | ||
} | ||
if (!!evmTransaction.gasLimit) { | ||
tx = { ...tx, gasLimit: evmTransaction.gasLimit }; | ||
} | ||
if (!!evmTransaction.gasPrice) { | ||
tx = { ...tx, gasPrice: evmTransaction.gasPrice }; | ||
} | ||
if (!!evmTransaction.nonce) { | ||
tx = { ...tx, nonce: evmTransaction.nonce }; | ||
} | ||
|
||
const tr = await signer.sendTransaction(tx); | ||
return tr.hash; | ||
} | ||
|
||
// Switch network | ||
// Make a transaction and run | ||
// check status from server | ||
// notif the resul |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.