-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ETHEREUM_PROVIDER env variable for cloudflare
- Loading branch information
Showing
17 changed files
with
4,514 additions
and
3,132 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,26 +1,18 @@ | ||
import * as ethers from "ethers"; | ||
import { INFURA_API_KEY } from "../../config"; | ||
import { Hash } from "../../types/core"; | ||
import { getLogger } from "../logger"; | ||
|
||
const logger = getLogger("contractInstance"); | ||
interface ContractInstance { | ||
abi: any; // type is any of json file in abi folder | ||
network: string; | ||
contractAddress: Hash; | ||
} | ||
|
||
export const getProvider = (options: { network: string }): ethers.providers.Provider => | ||
new ethers.providers.InfuraProvider(options.network, process?.env?.INFURA_API_KEY || INFURA_API_KEY); | ||
process.env.ETHEREUM_PROVIDER === "cloudflare" | ||
? new ethers.providers.CloudflareProvider() | ||
: new ethers.providers.InfuraProvider(options.network, process.env.INFURA_API_KEY || INFURA_API_KEY); | ||
|
||
export const contractInstance = (options: ContractInstance) => { | ||
const contract = new ethers.Contract(options.contractAddress, options.abi, getProvider(options)); | ||
|
||
// this is done to prevent uncaught exception to raise because an address is invalid | ||
contract.addressPromise.catch(() => { | ||
logger.trace( | ||
`oa-verify caught an error from ethers when trying to resolve the address of the provided address ${options.contractAddress}` | ||
); | ||
}); | ||
return contract; | ||
return new ethers.Contract(options.contractAddress, options.abi, getProvider(options)); | ||
}; |
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,2 +1 @@ | ||
// export const INFURA_API_KEY = "92c9a51428b946c1b8c1ac5a237616e4"; | ||
export const INFURA_API_KEY = "9f83339cff8c408093a75f98e0001b1a"; | ||
export const INFURA_API_KEY = "bb46da3f80e040e8ab73c0a9ff365d18"; |
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
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
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