Skip to content

Commit 2e3b525

Browse files
Add access key to rpc url (#529)
1 parent 3b83281 commit 2e3b525

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

packages/connect/src/config/createConfig.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const createConfig = <T extends WalletType>(walletType: T, options: Creat
2121
const { projectAccessKey, chainIds, wagmiConfig, ...rest } = options
2222

2323
const chains = wagmiConfig?.chains || getDefaultChains(chainIds)
24-
const transports = wagmiConfig?.transports || getDefaultTransports(chains)
24+
const transports = wagmiConfig?.transports || getDefaultTransports(chains, projectAccessKey)
2525
const connectors = wagmiConfig?.connectors || getDefaultConnectors(walletType, options)
2626

2727
return {
Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,29 @@
11
import { http, type Chain } from 'viem'
22

3-
export const getDefaultTransports = (chains: readonly [Chain, ...Chain[]]) => {
4-
return Object.fromEntries(chains.map(chain => [chain.id, http()]))
3+
const isSequenceNodeUrl = (url: string): boolean => {
4+
return url.includes('sequence.app')
5+
}
6+
7+
const appendAccessKey = (url: string, accessKey: string): string => {
8+
const cleanUrl = url.endsWith('/') ? url.slice(0, -1) : url
9+
if (url.endsWith(accessKey)) {
10+
return url
11+
}
12+
13+
return `${cleanUrl}/${accessKey}`
14+
}
15+
16+
export const getDefaultTransports = (chains: readonly [Chain, ...Chain[]], projectAccessKey?: string) => {
17+
return Object.fromEntries(
18+
chains.map(chain => {
19+
const rpcUrl = chain.rpcUrls.default.http[0]
20+
21+
if (projectAccessKey && rpcUrl && isSequenceNodeUrl(rpcUrl)) {
22+
const urlWithAccessKey = appendAccessKey(rpcUrl, projectAccessKey)
23+
return [chain.id, http(urlWithAccessKey)]
24+
}
25+
26+
return [chain.id, http()]
27+
})
28+
)
529
}

0 commit comments

Comments
 (0)