-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: AlchemyProvider class * chore: deleting yarn.lock * chore: fixing package.json * test: testing alchemy provider * Simplify alchemy provider * env cleanup * Improve testing logging errros * Remove excess dotenv --------- Co-authored-by: dawsbot <[email protected]>
- Loading branch information
Showing
9 changed files
with
50 additions
and
17 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
RPC_ORIGIN=https://free-eth-node.com | ||
# RPC_ORIGIN=http://localhost:3000 | ||
ALCHEMY_API_KEY=API_KEY_HERE |
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,3 +1,4 @@ | ||
.env | ||
node_modules | ||
lib | ||
dist | ||
|
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,8 @@ | ||
import { JsonRpcProvider } from './JsonRpcProvider'; | ||
|
||
export class AlchemyProvider extends JsonRpcProvider { | ||
constructor(apiKey: string, network = 'mainnet') { | ||
const alchemyUrl = `https://eth-${network}.alchemyapi.io/v2/${apiKey}`; | ||
super(alchemyUrl); | ||
} | ||
} |
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,12 +1,18 @@ | ||
import z from 'zod'; | ||
export const fakeUrls = { | ||
notRPCButRealHttp: 'https://httpstat.us/200', | ||
} as const; | ||
|
||
const RPC_ORIGIN = process.env.RPC_ORIGIN; | ||
if (!z.string().url().safeParse(RPC_ORIGIN).success) { | ||
throw new Error('RPC_ORIGIN is not defined or is invalid URL'); | ||
} | ||
|
||
export const rpcUrls = { | ||
mainnet: `${process.env.RPC_ORIGIN}/api/eth`, | ||
matic: `${process.env.RPC_ORIGIN}/api/MATIC`, | ||
gno: `${process.env.RPC_ORIGIN}/api/gno`, | ||
bnb: `${process.env.RPC_ORIGIN}/api/bnb`, | ||
arb1: `${process.env.RPC_ORIGIN}/api/arb1`, | ||
gor: `${process.env.RPC_ORIGIN}/api/gor`, | ||
mainnet: `${RPC_ORIGIN}/api/eth`, | ||
matic: `${RPC_ORIGIN}/api/MATIC`, | ||
gno: `${RPC_ORIGIN}/api/gno`, | ||
bnb: `${RPC_ORIGIN}/api/bnb`, | ||
arb1: `${RPC_ORIGIN}/api/arb1`, | ||
gor: `${RPC_ORIGIN}/api/gor`, | ||
}; |
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,19 @@ | ||
import { z } from 'zod'; | ||
import { AlchemyProvider, TinyBig } from '../../index'; | ||
|
||
const ALCHEMY_API_KEY = process.env.ALCHEMY_API_KEY; | ||
|
||
if (!ALCHEMY_API_KEY) { | ||
throw new Error( | ||
'ALCHEMY_API_KEY is not defined in the environment variables.', | ||
); | ||
} | ||
|
||
const provider = new AlchemyProvider(ALCHEMY_API_KEY); | ||
|
||
describe('alchemyProvider.getGasPrice', () => { | ||
it('should return the current gas price', async () => { | ||
const gasPrice = await provider.getGasPrice(); | ||
expect(z.instanceof(TinyBig).safeParse(gasPrice).success).toBe(true); | ||
}); | ||
}); |