Skip to content

Commit f30ace6

Browse files
committed
Added to getChainConfig to all examples
1 parent 99458ca commit f30ace6

File tree

47 files changed

+185
-546
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+185
-546
lines changed

web-modal-sdk/account-abstraction-examples/aa-modal-quick-start/src/App.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./App.css";
22

3-
import { CHAIN_NAMESPACES, IProvider, WEB3AUTH_NETWORK } from "@web3auth/base";
3+
import { IProvider, WEB3AUTH_NETWORK, getEvmChainConfig } from "@web3auth/base";
44
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
55
import { AccountAbstractionProvider, SafeSmartAccount } from "@web3auth/account-abstraction-provider";
66
import { Web3Auth, Web3AuthOptions } from "@web3auth/modal";
@@ -11,16 +11,8 @@ import RPC from "./ethersRPC";
1111

1212
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io
1313

14-
const chainConfig = {
15-
chainNamespace: CHAIN_NAMESPACES.EIP155,
16-
chainId: "0xaa36a7",
17-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
18-
displayName: "Ethereum Sepolia Testnet",
19-
blockExplorerUrl: "https://sepolia.etherscan.io",
20-
ticker: "ETH",
21-
tickerName: "Ethereum",
22-
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
23-
};
14+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
15+
const chainConfig = getEvmChainConfig(0xaa36a7)!;
2416

2517
const pimlicoAPIKey = import.meta.env.VITE_API_KEY;
2618

@@ -139,7 +131,7 @@ function App() {
139131
uiConsole(signature);
140132
};
141133

142-
function uiConsole(...args: any[]): void {
134+
function uiConsole(...args: unknown[]): void {
143135
const el = document.querySelector("#console>p");
144136
if (el) {
145137
el.innerHTML = JSON.stringify(args || {}, null, 2);

web-modal-sdk/account-abstraction-examples/biconomy-modal-example/src/App.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./App.css";
22

3-
import { CHAIN_NAMESPACES, IProvider, WEB3AUTH_NETWORK } from "@web3auth/base";
3+
import { IProvider, WEB3AUTH_NETWORK, getEvmChainConfig } from "@web3auth/base";
44
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
55
import { AccountAbstractionProvider, BiconomySmartAccount } from "@web3auth/account-abstraction-provider";
66
import { Web3Auth, Web3AuthOptions } from "@web3auth/modal";
@@ -10,16 +10,8 @@ import RPC from "./ethersRPC";
1010

1111
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io
1212

13-
const chainConfig = {
14-
chainNamespace: CHAIN_NAMESPACES.EIP155,
15-
chainId: "0xaa36a7",
16-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
17-
displayName: "Ethereum Sepolia Testnet",
18-
blockExplorerUrl: "https://sepolia.etherscan.io",
19-
ticker: "ETH",
20-
tickerName: "Ethereum",
21-
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
22-
};
13+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
14+
const chainConfig = getEvmChainConfig(0xaa36a7)!;
2315

2416
const pimlicoAPIKey = import.meta.env.VITE_API_KEY;
2517

@@ -137,7 +129,7 @@ function App() {
137129
uiConsole(signature);
138130
};
139131

140-
function uiConsole(...args: any[]): void {
132+
function uiConsole(...args: unknown[]): void {
141133
const el = document.querySelector("#console>p");
142134
if (el) {
143135
el.innerHTML = JSON.stringify(args || {}, null, 2);

web-modal-sdk/account-abstraction-examples/safe-modal-example/src/App.tsx

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "./App.css";
22

3-
import { CHAIN_NAMESPACES, IProvider, WEB3AUTH_NETWORK } from "@web3auth/base";
3+
import { IProvider, WEB3AUTH_NETWORK, getEvmChainConfig } from "@web3auth/base";
44
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
55
import { AccountAbstractionProvider, SafeSmartAccount } from "@web3auth/account-abstraction-provider";
66
import { Web3Auth, Web3AuthOptions } from "@web3auth/modal";
@@ -10,16 +10,8 @@ import RPC from "./ethersRPC";
1010

1111
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io
1212

13-
const chainConfig = {
14-
chainNamespace: CHAIN_NAMESPACES.EIP155,
15-
chainId: "0xaa36a7",
16-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
17-
displayName: "Ethereum Sepolia Testnet",
18-
blockExplorerUrl: "https://sepolia.etherscan.io",
19-
ticker: "ETH",
20-
tickerName: "Ethereum",
21-
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
22-
};
13+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
14+
const chainConfig = getEvmChainConfig(0xaa36a7)!;
2315

2416
const pimlicoAPIKey = import.meta.env.VITE_API_KEY;
2517

@@ -137,7 +129,7 @@ function App() {
137129
uiConsole(signature);
138130
};
139131

140-
function uiConsole(...args: any[]): void {
132+
function uiConsole(...args: unknown[]): void {
141133
const el = document.querySelector("#console>p");
142134
if (el) {
143135
el.innerHTML = JSON.stringify(args || {}, null, 2);

web-modal-sdk/blockchain-connection-examples/evm-modal-example/src/App.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,15 @@
11
import { useEffect, useState } from "react";
22
import { useWeb3Auth } from "@web3auth/modal-react-hooks";
3-
import { CHAIN_NAMESPACES, IProvider } from "@web3auth/base";
3+
import { IProvider, getEvmChainConfig } from "@web3auth/base";
44

55
import "./App.css";
66
// import RPC from "./web3RPC"; // for using web3.js
77
import RPC from "./viemRPC"; // for using viem
88
// import RPC from "./ethersRPC"; // for using ethers.js
99
import { useWalletServicesPlugin } from "@web3auth/wallet-services-plugin-react-hooks";
1010

11-
const newChain = {
12-
chainNamespace: CHAIN_NAMESPACES.EIP155,
13-
chainId: "0x89", // hex of 137, polygon mainnet
14-
rpcTarget: "https://rpc.ankr.com/polygon",
15-
// Avoid using public rpcTarget in production.
16-
// Use services like Infura, Quicknode etc
17-
displayName: "Polygon Mainnet",
18-
blockExplorerUrl: "https://polygonscan.com",
19-
ticker: "POL",
20-
tickerName: "Polygon Ecosystem token",
21-
logo: "https://images.toruswallet.io/polygon.svg",
22-
};
11+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
12+
const newChain = getEvmChainConfig(0x13881)!;
2313

2414
function App() {
2515
const {

web-modal-sdk/blockchain-connection-examples/evm-modal-example/src/web3AuthProviderProps.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,13 @@
11
import { Web3AuthContextConfig } from "@web3auth/modal-react-hooks";
22
import { Web3AuthOptions } from "@web3auth/modal";
33
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
4-
import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } from "@web3auth/base";
4+
import { WEB3AUTH_NETWORK, getEvmChainConfig } from "@web3auth/base";
55
import { AuthAdapter } from "@web3auth/auth-adapter";
66
import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin";
77
import { getDefaultExternalAdapters } from "@web3auth/default-evm-adapter";
88

9-
const chainConfig = {
10-
chainId: "0xaa36a7", // for wallet connect make sure to pass in this chain in the loginSettings of the adapter.
11-
displayName: "Ethereum Sepolia",
12-
chainNamespace: CHAIN_NAMESPACES.EIP155,
13-
tickerName: "Ethereum Sepolia",
14-
ticker: "ETH",
15-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
16-
blockExplorerUrl: "https://sepolia.etherscan.io",
17-
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
18-
};
9+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
10+
const chainConfig = getEvmChainConfig(0xaa36a7)!;
1911

2012
const privateKeyProvider = new EthereumPrivateKeyProvider({
2113
config: {

web-modal-sdk/blockchain-connection-examples/solana-modal-example/src/App.tsx

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from "react";
22
import { Web3Auth } from "@web3auth/modal";
3-
import { CHAIN_NAMESPACES, IAdapter, IProvider, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from "@web3auth/base";
3+
import { CHAIN_NAMESPACES, IAdapter, IProvider, WALLET_ADAPTERS, WEB3AUTH_NETWORK, getSolanaChainConfig } from "@web3auth/base";
44

55
import RPC from "./solanaRPC";
66
import "./App.css";
@@ -16,16 +16,8 @@ function App() {
1616
const [provider, setProvider] = useState<IProvider | null>(null);
1717
const [loggedIn, setLoggedIn] = useState(false);
1818

19-
const chainConfig = {
20-
chainId: "0x1",
21-
chainNamespace: CHAIN_NAMESPACES.SOLANA,
22-
rpcTarget: "https://api.devnet.solana.com",
23-
tickerName: "SOLANA",
24-
ticker: "SOL",
25-
decimals: 9,
26-
blockExplorerUrl: "https://explorer.solana.com/?cluster=devnet",
27-
logo: "https://images.toruswallet.io/sol.svg",
28-
};
19+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
20+
const chainConfig = getSolanaChainConfig(0x2)!;
2921

3022
useEffect(() => {
3123
const init = async () => {
@@ -157,17 +149,8 @@ function App() {
157149
return;
158150
}
159151

160-
const chainConfig = {
161-
chainId: "0x2",
162-
displayName: "Solana Testnet",
163-
chainNamespace: CHAIN_NAMESPACES.SOLANA,
164-
tickerName: "SOLANA",
165-
ticker: "SOL",
166-
decimals: 18,
167-
rpcTarget: "https://api.testnet.solana.com",
168-
blockExplorerUrl: "https://explorer.solana.com/?cluster=testnet",
169-
logo: "https://images.toruswallet.io/sol.svg",
170-
};
152+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
153+
const chainConfig = getSolanaChainConfig(0x3)!;
171154

172155
await web3auth?.addChain(chainConfig);
173156
uiConsole("New Chain Added");
@@ -178,7 +161,7 @@ function App() {
178161
uiConsole("provider not initialized yet");
179162
return;
180163
}
181-
await web3auth?.switchChain({ chainId: "0x2" });
164+
await web3auth?.switchChain({ chainId: "0x3" });
182165
uiConsole("Chain Switched");
183166
};
184167

web-modal-sdk/blockchain-connection-examples/xrpl-modal-example/src/App.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useState } from "react";
22
import { Web3Auth } from "@web3auth/modal";
3-
import { CHAIN_NAMESPACES, IProvider, UX_MODE, WEB3AUTH_NETWORK } from "@web3auth/base";
3+
import { IProvider, UX_MODE, WEB3AUTH_NETWORK, getXrplChainConfig } from "@web3auth/base";
44
import { AuthAdapter } from "@web3auth/auth-adapter";
55
import { XrplPrivateKeyProvider } from "@web3auth/xrpl-provider";
66
import RPC from "./xrplRPC";
@@ -13,18 +13,8 @@ function App() {
1313
const [provider, setProvider] = useState<IProvider | null>(null);
1414
const [loggedIn, setLoggedIn] = useState(false);
1515

16-
const chainConfig = {
17-
chainNamespace: CHAIN_NAMESPACES.XRPL,
18-
chainId: "0x2",
19-
// Avoid using public rpcTarget & wsTarget in production.
20-
// Use services like Infura, Quicknode etc
21-
rpcTarget: "https://ripple-node.tor.us",
22-
wsTarget: "wss://s2.ripple.com",
23-
ticker: "XRP",
24-
tickerName: "XRPL",
25-
displayName: "xrpl mainnet",
26-
blockExplorerUrl: "https://livenet.xrpl.org",
27-
};
16+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
17+
const chainConfig = getXrplChainConfig(0x1)!;
2818

2919
useEffect(() => {
3020
const init = async () => {

web-modal-sdk/custom-authentication-modal-example/src/App.tsx

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { useEffect, useState } from "react";
22
import { Web3Auth } from "@web3auth/modal";
33
// eslint-disable-next-line @typescript-eslint/no-unused-vars
4-
import { CHAIN_NAMESPACES, IProvider, WALLET_ADAPTERS, WEB3AUTH_NETWORK } from "@web3auth/base";
4+
import { IProvider, WALLET_ADAPTERS, WEB3AUTH_NETWORK, getEvmChainConfig } from "@web3auth/base";
55
import { AuthAdapter } from "@web3auth/auth-adapter";
66
import "./App.css";
77
//import RPC from "./web3RPC"; // for using web3.js
@@ -13,6 +13,7 @@ import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
1313
import { WalletServicesPlugin } from "@web3auth/wallet-services-plugin";
1414

1515
const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ"; // get from https://dashboard.web3auth.io
16+
const chainId = 0x13881;
1617

1718
function App() {
1819
const [web3auth, setWeb3auth] = useState<Web3Auth | null>(null);
@@ -23,16 +24,11 @@ function App() {
2324
useEffect(() => {
2425
const init = async () => {
2526
try {
26-
const chainConfig = {
27-
chainId: "0x1", // Please use 0x1 for Mainnet
28-
rpcTarget: "https://rpc.ankr.com/eth",
29-
chainNamespace: CHAIN_NAMESPACES.EIP155,
30-
displayName: "Ethereum Mainnet",
31-
blockExplorerUrl: "https://etherscan.io/",
32-
ticker: "ETH",
33-
tickerName: "Ethereum",
34-
logo: "https://images.toruswallet.io/eth.svg",
35-
};
27+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
28+
const chainConfig = getEvmChainConfig(chainId);
29+
if (!chainConfig) {
30+
throw new Error(`Chain configuration not found for chainId: ${chainId}`);
31+
}
3632

3733
const privateKeyProvider = new EthereumPrivateKeyProvider({ config: { chainConfig: chainConfig } });
3834

@@ -290,17 +286,13 @@ function App() {
290286
uiConsole("provider not initialized yet");
291287
return;
292288
}
293-
const newChain = {
294-
chainNamespace: CHAIN_NAMESPACES.EIP155,
295-
chainId: "0xaa36a7", // hex for 11155111
296-
displayName: "Ethereum Sepolia",
297-
tickerName: "Ethereum",
298-
ticker: "ETH",
299-
decimals: 18,
300-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
301-
blockExplorerUrl: "https://sepolia.etherscan.io",
302-
logo: "https://images.toruswallet.io/eth.svg",
303-
};
289+
const newchainId = 0xaa36a7;
290+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
291+
const newChain = getEvmChainConfig(newchainId);
292+
if (!newChain) {
293+
uiConsole(`Chain configuration not found for chainId: ${newchainId}`);
294+
return;
295+
}
304296
await web3auth?.addChain(newChain);
305297
uiConsole("New Chain Added");
306298
};

web-modal-sdk/quick-starts/angular-modal-quick-start/src/app/app.component.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component } from "@angular/core";
22
// IMP START - Quick Start
3-
import { CHAIN_NAMESPACES, IAdapter, IProvider, WEB3AUTH_NETWORK } from "@web3auth/base";
3+
import { IAdapter, IProvider, WEB3AUTH_NETWORK, getEvmChainConfig } from "@web3auth/base";
44
import { Web3Auth, Web3AuthOptions } from "@web3auth/modal";
55
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
66
import { getDefaultExternalAdapters } from "@web3auth/default-evm-adapter";
@@ -17,18 +17,8 @@ const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw
1717
// IMP END - Dashboard Registration
1818

1919
// IMP START - Chain Config
20-
const chainConfig = {
21-
chainNamespace: CHAIN_NAMESPACES.EIP155,
22-
chainId: "0xaa36a7",
23-
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
24-
// Avoid using public rpcTarget in production.
25-
// Use services like Infura, Quicknode etc
26-
displayName: "Ethereum Sepolia Testnet",
27-
blockExplorerUrl: "https://sepolia.etherscan.io",
28-
ticker: "ETH",
29-
tickerName: "Ethereum",
30-
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
31-
};
20+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
21+
const chainConfig = getEvmChainConfig(0xaa36a7)!;
3222
// IMP END - Chain Config
3323

3424
// IMP START - SDK Initialization
@@ -153,7 +143,7 @@ export class AppComponent {
153143
};
154144
// IMP END - Blockchain Calls
155145

156-
uiConsole(...args: any[]) {
146+
uiConsole(...args: unknown[]) {
157147
const el = document.querySelector("#console-ui>p");
158148
if (el) {
159149
el.innerHTML = JSON.stringify(args || {}, null, 2);

web-modal-sdk/quick-starts/nextjs-modal-quick-start/app/page.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ const clientId = "BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw
2222
// IMP END - Dashboard Registration
2323

2424
// IMP START - Chain Config
25-
const chainId = 11155111; // Sepolia testnet
26-
const chainConfig = getEvmChainConfig(chainId, clientId)!;
25+
const chainId = 0xaa36a7; // Sepolia testnet
26+
// Get custom chain configs for your chain from https://web3auth.io/docs/connect-blockchain
27+
const chainConfig = getEvmChainConfig(chainId)!;
2728
// IMP END - Chain Config
2829

2930
// IMP START - SDK Initialization

0 commit comments

Comments
 (0)