Skip to content

Commit ec2a88e

Browse files
authored
feat: update getInfuraRpcUrls to return eip155 entries keyed as hex chain IDs in the connect-evm package (#152)
* reexport getInfuraRpcUrls keyed by hex chain id * changelog * missed a file * fix type
1 parent 9f622ab commit ec2a88e

3 files changed

Lines changed: 27 additions & 1 deletion

File tree

packages/connect-evm/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- `switchChain()` now expects `chainId: Hex` instead of `chainId: number | Hex`
1616
- `createEVMClient()` param option `api.supportedNetworks` now expects hex chain IDs as keys (e.g., `'0x1'`) instead of CAIP chain IDs
1717
- Event handler types for `connectAndSign` and `connectWith` now use `Hex` for `chainId`
18+
- **BREAKING** `getInfuraRpcUrls` now returns a rpc url map keyed by hex chain ID rather than CAIP Chain ID ([#152](https://github.com/MetaMask/connect-monorepo/pull/152))
1819
- The `debug` option param used by `createEVMClient()` now enables console debug logs of the underlying `MultichainClient` instance. ([#149](https://github.com/MetaMask/connect-monorepo/pull/149))
1920

2021
## [0.4.1]

packages/connect-evm/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export { getInfuraRpcUrls } from '@metamask/connect-multichain';
1+
export { getInfuraRpcUrls } from './utils/infura';
22
export { createEVMClient, type MetamaskConnectEVM } from './connect';
33
export type { EIP1193Provider } from './provider';
44

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import type { RpcUrlsMap } from '@metamask/connect-multichain';
2+
import { getInfuraRpcUrls as getInfuraRpcUrlsMultichain } from '@metamask/connect-multichain';
3+
import type { CaipChainId, Hex } from '@metamask/utils';
4+
import {
5+
KnownCaipNamespace,
6+
numberToHex,
7+
parseCaipChainId,
8+
} from '@metamask/utils';
9+
10+
export const getInfuraRpcUrls = (infuraAPIKey: string): RpcUrlsMap => {
11+
const caipMap = getInfuraRpcUrlsMultichain(infuraAPIKey);
12+
const hexMap = Object.entries(caipMap).reduce<Record<Hex, string>>(
13+
(acc, [key, url]) => {
14+
const { namespace, reference } = parseCaipChainId(key as CaipChainId);
15+
if (namespace !== KnownCaipNamespace.Eip155) {
16+
return acc;
17+
}
18+
const chainId = numberToHex(parseInt(reference, 10));
19+
acc[chainId] = url as string;
20+
return acc;
21+
},
22+
{},
23+
);
24+
return hexMap;
25+
};

0 commit comments

Comments
 (0)