-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add TransactionProvider to pass data down
- Loading branch information
Showing
6 changed files
with
95 additions
and
10 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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import React, { useEffect, useState } from 'react'; | ||
import { ethers } from 'ethers'; | ||
import { contractABI, contractAddress } from '../utils/constants'; | ||
|
||
// create a context for transactions with no default value | ||
export const TransactionContext = React.createContext(); | ||
|
||
// window.ethereum is enabled thanks to our Metamask extension | ||
const { ethereum } = window; | ||
|
||
const getEthereumContract = () => { | ||
const provider = new ethers.providers.Web3Provider(ethereum); | ||
const signer = provider.getSigner(); | ||
const transactionContract = new ethers.Contract( | ||
contractAddress, | ||
contractABI, | ||
signer | ||
); | ||
|
||
console.log({ provider, signer, transactionContract }); | ||
}; | ||
|
||
export const TransactionProvider = ({ children }) => { | ||
return ( | ||
// using TransactionContext defined above, .Provider allows us to set | ||
// a value to pass down to all of the children | ||
<TransactionContext.Provider value='test'> | ||
{children} | ||
</TransactionContext.Provider> | ||
); | ||
}; |
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,11 +1,12 @@ | ||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import './index.css' | ||
import App from './App' | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import './index.css'; | ||
import App from './App'; | ||
import { TransactionProvider } from './context/TransactionContext'; | ||
|
||
ReactDOM.render( | ||
<React.StrictMode> | ||
<App /> | ||
</React.StrictMode>, | ||
document.getElementById('root') | ||
) | ||
<TransactionProvider> | ||
<App /> | ||
</TransactionProvider>, | ||
document.getElementById('root') | ||
); |
File renamed without changes.
File renamed without changes.