-
Notifications
You must be signed in to change notification settings - Fork 2
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
6592ded
commit d277977
Showing
7 changed files
with
77 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
All atoms shoul be created in this folder |
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 @@ | ||
All reusable hooks should be created under this folder |
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,14 @@ | ||
import Web3Service from "./service"; | ||
|
||
class Web3Actions { | ||
public async connectWallet() { | ||
const web3Instance = new Web3Service(); | ||
const signer = await web3Instance.connect(); | ||
|
||
console.log(signer); | ||
} | ||
} | ||
|
||
const web3Actions = new Web3Actions(); | ||
|
||
export default web3Actions; |
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,28 +1,4 @@ | ||
import { ethers } from "ethers"; | ||
import { TChain } from "../../types/chains"; | ||
import { CHAINS_ENV } from "../config/chains"; | ||
import NFTABI from "../web3/abis/NFT.json"; | ||
class Web3Instance { | ||
public provider; | ||
import web3Actions from "./actions"; | ||
import Web3Service from "./service"; | ||
|
||
constructor() { | ||
this.provider = new ethers.providers.JsonRpcProvider( | ||
CHAINS_ENV.polygon.nodeRPC | ||
); | ||
} | ||
|
||
public contract(chain: TChain = "polygon") { | ||
const network = this.getChainByName(chain); | ||
return new ethers.Contract( | ||
network.mintContractAddress, | ||
NFTABI, | ||
this.provider | ||
); | ||
} | ||
|
||
public getChainByName(chain: TChain = "polygon") { | ||
return CHAINS_ENV[chain]; | ||
} | ||
} | ||
|
||
export default Web3Instance; | ||
export { Web3Service, web3Actions }; |
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,47 @@ | ||
import { ethers } from "ethers"; | ||
import { TChain } from "../../types/chains"; | ||
import { CHAINS_ENV } from "../config/chains"; | ||
import NFTABI from "./abis/NFT.json"; | ||
|
||
class Web3Service { | ||
public provider; | ||
|
||
constructor() { | ||
// Initial implementation of connecting to the blockchain with an hardcoded chain | ||
this.provider = new ethers.providers.JsonRpcProvider( | ||
CHAINS_ENV.polygon.nodeRPC | ||
); | ||
} | ||
|
||
public contract(chain: TChain = "polygon") { | ||
const network = this.getChainByName(chain); | ||
return new ethers.Contract( | ||
network.mintContractAddress, | ||
NFTABI, | ||
this.provider | ||
); | ||
} | ||
|
||
public getChainByName(chain: TChain = "polygon") { | ||
return CHAINS_ENV[chain]; | ||
} | ||
|
||
/** | ||
* Hey folks, this is just the initial way of connecting wallet with support to MetaMask. | ||
* It should be improved to support other wallets. | ||
* @returns signer - The currently connected user | ||
*/ | ||
public async connect() { | ||
if (window && !window?.ethereum) | ||
return new Error("Browser does not support Web3"); | ||
|
||
const provider = new ethers.providers.Web3Provider(window.ethereum); | ||
|
||
await provider.send("eth_requestAccounts", []); | ||
|
||
const signer = provider.getSigner(); | ||
return signer; | ||
} | ||
} | ||
|
||
export default Web3Service; |
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,7 @@ | ||
export {}; | ||
|
||
declare global { | ||
interface Window { | ||
ethereum: any; | ||
} | ||
} |