generated from dgma/nodejs-web3-starter
-
Notifications
You must be signed in to change notification settings - Fork 0
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
74bcf71
commit dc38ca5
Showing
10 changed files
with
85 additions
and
57 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 was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* The supported networks by Alchemy. Note that some functions are not available | ||
* on all networks. Please refer to the Alchemy documentation for which APIs are | ||
* available on which networks | ||
* {@link https://docs.alchemy.com/alchemy/apis/feature-support-by-chain} | ||
* | ||
* @public | ||
*/ | ||
export enum Network { | ||
ETH_MAINNET = "eth-mainnet", | ||
ETH_GOERLI = "eth-goerli", | ||
ETH_SEPOLIA = "eth-sepolia", | ||
OPT_MAINNET = "opt-mainnet", | ||
OPT_GOERLI = "opt-goerli", | ||
OPT_SEPOLIA = "opt-sepolia", | ||
ARB_MAINNET = "arb-mainnet", | ||
ARB_GOERLI = "arb-goerli", | ||
ARB_SEPOLIA = "arb-sepolia", | ||
MATIC_MAINNET = "polygon-mainnet", | ||
MATIC_MUMBAI = "polygon-mumbai", | ||
MATIC_AMOY = "polygon-amoy", | ||
ASTAR_MAINNET = "astar-mainnet", | ||
POLYGONZKEVM_MAINNET = "polygonzkevm-mainnet", | ||
POLYGONZKEVM_TESTNET = "polygonzkevm-testnet", | ||
BASE_MAINNET = "base-mainnet", | ||
BASE_GOERLI = "base-goerli", | ||
BASE_SEPOLIA = "base-sepolia", | ||
ZKSYNC_MAINNET = "zksync-mainnet", | ||
ZKSYNC_SEPOLIA = "zksync-sepolia", | ||
} |
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,41 @@ | ||
import { AxiosInstance } from "axios"; | ||
import { createWalletClient, http, publicActions, custom, createPublicClient } from "viem"; | ||
import * as chains from "viem/chains"; | ||
import getEnv from "src/env"; | ||
import { Network as AlchemyNetwork } from "src/libs/alchemy"; | ||
|
||
type ChainIdToAlchemyNetworksMap = { | ||
[prop: number]: AlchemyNetwork; | ||
}; | ||
|
||
const chainIdToAlchemyNetworksMap: ChainIdToAlchemyNetworksMap = { | ||
[chains.mainnet.id]: AlchemyNetwork.ETH_MAINNET, | ||
}; | ||
|
||
const transport = (chain: chains.Chain, proxy?: AxiosInstance) => { | ||
if (!proxy) { | ||
return http(); | ||
} | ||
|
||
return custom({ | ||
async request(body: { method: string; params: any[] }) { | ||
const response = await proxy.post( | ||
`https://${chainIdToAlchemyNetworksMap[chain.id]}.g.alchemy.com/v2/${getEnv("ALCHEMY_RPC_KEY")}`, | ||
body, | ||
); | ||
return response.data; | ||
}, | ||
}); | ||
}; | ||
|
||
export const getPublicClient = (chain: chains.Chain) => | ||
createPublicClient({ | ||
chain, | ||
transport: http(), | ||
}); | ||
|
||
export const getClient = (chain: chains.Chain, proxy: AxiosInstance) => | ||
createWalletClient({ | ||
chain, | ||
transport: transport(chain, proxy), | ||
}).extend(publicActions); |
This file was deleted.
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
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 was deleted.
Oops, something went wrong.