Skip to content

Commit

Permalink
Merge pull request #1977 from Web3Auth/update-matic
Browse files Browse the repository at this point in the history
Update Polygon Chain Details
  • Loading branch information
chaitanyapotti authored Oct 9, 2024
2 parents 9defd01 + 6bed43d commit ba9ef6d
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 75 deletions.
8 changes: 4 additions & 4 deletions demo/react-app/src/config/chainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const CHAIN_CONFIG = {
blockExplorerUrl: "https://polygonscan.com/",
chainId: "0x89",
displayName: "Polygon Mainnet",
ticker: "matic",
tickerName: "Matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
logo: "https://images.toruswallet.io/matic.svg",
chainNamespace: CHAIN_NAMESPACES.EIP155,
} as CustomChainConfig,
Expand All @@ -36,8 +36,8 @@ export const CHAIN_CONFIG = {
blockExplorerUrl: "https://amoy.polygonscan.com/",
chainId: "0x13882",
displayName: "Polygon Amoy Testnet",
ticker: "matic",
tickerName: "Matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
logo: "https://images.toruswallet.io/matic.svg",
chainNamespace: CHAIN_NAMESPACES.EIP155,
} as CustomChainConfig,
Expand Down
4 changes: 2 additions & 2 deletions demo/react-app/src/services/web3auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,8 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
blockExplorerUrl: "https://polygonscan.com/",
chainId: "0x89",
displayName: "Polygon Mainnet",
ticker: "matic",
tickerName: "Matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
logo: "https://images.toruswallet.io/matic.svg",
chainNamespace: CHAIN_NAMESPACES.EIP155,
};
Expand Down
8 changes: 4 additions & 4 deletions demo/vite-react-app/src/config/chainConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ export const CHAIN_CONFIG = {
blockExplorerUrl: "https://polygonscan.com/",
chainId: "0x89",
displayName: "Polygon Mainnet",
ticker: "matic",
tickerName: "Matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
logo: "https://images.toruswallet.io/matic.svg",
chainNamespace: CHAIN_NAMESPACES.EIP155,
} as CustomChainConfig,
Expand All @@ -36,8 +36,8 @@ export const CHAIN_CONFIG = {
blockExplorerUrl: "https://amoy.polygonscan.com/",
chainId: "0x13882",
displayName: "Polygon Amoy Testnet",
ticker: "matic",
tickerName: "Matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
logo: "https://images.toruswallet.io/matic.svg",
chainNamespace: CHAIN_NAMESPACES.EIP155,
} as CustomChainConfig,
Expand Down
4 changes: 2 additions & 2 deletions demo/vite-react-app/src/services/web3auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ export const Web3AuthProvider: FunctionComponent<IWeb3AuthState> = ({ children,
blockExplorerUrl: "https://polygonscan.com/",
chainId: "0x89",
displayName: "Polygon Mainnet",
ticker: "matic",
tickerName: "Matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
logo: "https://images.toruswallet.io/matic.svg",
chainNamespace: CHAIN_NAMESPACES.EIP155,
};
Expand Down
13 changes: 6 additions & 7 deletions demo/vue-app-new/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,12 @@ export const chainConfigs: Record<ChainNamespaceType, CustomChainConfig[]> = {
},
{
chainNamespace: CHAIN_NAMESPACES.EIP155,
rpcTarget: "https://rpc-mumbai.maticvigil.com",
blockExplorerUrl: "https://mumbai-explorer.matic.today",
logo: "https://cryptologos.cc/logos/polygon-matic-logo.png",
chainId: "0x13881",
displayName: "Polygon Mumbai Testnet",
ticker: "matic",
tickerName: "matic",
chainId: "0x13882",
rpcTarget: "https://rpc.ankr.com/polygon_amoy",
displayName: "Polygon Amoy Testnet",
blockExplorerUrl: "https://amoy.polygonscan.com/",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
},
],
[CHAIN_NAMESPACES.SOLANA]: [
Expand Down
20 changes: 11 additions & 9 deletions demo/vue-app/src/chains/matic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,17 @@ import config from "../config";
import EthRpc from "../rpc/ethRpc.vue";
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const polygonMumbaiConfig: any = {
const polygonAmoyConfig: any = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
rpcTarget: "https://rpc-mumbai.maticvigil.com",
blockExplorerUrl: "https://mumbai-explorer.matic.today",
chainId: "0x13882", // hex of 80002, polygon testnet
rpcTarget: "https://rpc.ankr.com/polygon_amoy",
// Avoid using public rpcTarget in production.
// Use services like Infura, Quicknode etc
displayName: "Polygon Amoy Testnet",
blockExplorerUrl: "https://amoy.polygonscan.com/",
logo: "https://cryptologos.cc/logos/polygon-matic-logo.png",
chainId: "0x13881",
displayName: "Polygon Mumbai Testnet",
ticker: "matic",
tickerName: "matic",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
};
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand All @@ -59,9 +61,9 @@ const ethereumChainConfig: any = {
};
const polygonWeb3AuthOptions: Web3AuthOptions = {
chainConfig: polygonMumbaiConfig,
chainConfig: polygonAmoyConfig,
clientId: config.clientId.testnet,
privateKeyProvider: new EthereumPrivateKeyProvider({ config: { chainConfig: polygonMumbaiConfig } }),
privateKeyProvider: new EthereumPrivateKeyProvider({ config: { chainConfig: polygonAmoyConfig } }),
enableLogging: true,
};
Expand Down
20 changes: 16 additions & 4 deletions packages/base/src/chain/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ export const getEvmChainConfig = (chainId: number): CustomChainConfig | null =>
rpcTarget: "https://rpc.ankr.com/polygon",
displayName: "Polygon Mainnet",
blockExplorerUrl: "https://polygonscan.com",
ticker: "MATIC",
tickerName: "Polygon",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
};
}
if (chainId === 80002) {
Expand All @@ -72,8 +72,8 @@ export const getEvmChainConfig = (chainId: number): CustomChainConfig | null =>
rpcTarget: "https://rpc.ankr.com/polygon_amoy",
displayName: "Polygon Amoy Testnet",
blockExplorerUrl: "https://www.oklink.com/amoy",
ticker: "MATIC",
tickerName: "Polygon",
ticker: "POL",
tickerName: "Polygon Ecosystem Token",
decimals: 18,
};
}
Expand Down Expand Up @@ -141,6 +141,18 @@ export const getEvmChainConfig = (chainId: number): CustomChainConfig | null =>
decimals: 18,
};
}
if (chainId === 1946) {
return {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0x79a",
rpcTarget: "https://rpc.minato.soneium.org",
displayName: "Soneium Minato Testnet",
blockExplorerUrl: "https://explorer-testnet.soneium.org",
ticker: "ETH",
tickerName: "ETH",
logo: "https://cryptologos.cc/logos/soneium-logo.png",
};
}

return null;
};
Expand Down
45 changes: 23 additions & 22 deletions packages/providers/ethereum-mpc-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,31 @@ npm install --save @web3auth/ethereum-mpc-provider
## 🩹 Example

```ts
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-mpc-provider";
import type { SafeEventEmitterProvider } from "@web3auth/base";
const signEthMessage = async (provider: SafeEventEmitterProvider): Promise<string> => {
const web3 = new Web3(provider as any);
const accounts = await web3.eth.getAccounts();
// hex message
const message = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad";
const signature = await web3.eth.sign(message, accounts[0]);
return signature;
import { Web3AuthMPCCoreKit, WEB3AUTH_NETWORK, makeEthereumSigner } from "@web3auth/mpc-core-kit";
import { EthereumSigningProvider } from '@web3auth/ethereum-mpc-provider';
import { CHAIN_NAMESPACES } from "@web3auth/base";

const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0x1", // Please use 0x1 for Mainnet
rpcTarget: "https://rpc.ankr.com/eth",
displayName: "Ethereum Mainnet",
blockExplorer: "https://etherscan.io/",
ticker: "ETH",
tickerName: "Ethereum",
};

(async () => {
const provider = await EthereumPrivateKeyProvider.getProviderInstance({
chainConfig: {
rpcTarget: "https://polygon-rpc.com",
chainId: "0x89", // hex chain id
networkName: "matic",
ticker: "matic",
tickerName: "matic",
},
privKey: "4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318",
});
const signedMessage = await signEthMessage(provider);
})();
const coreKitInstance = new Web3AuthMPCCoreKit({
web3AuthClientId: "YOUR_WEB3AUTH_CLIENT_ID",
web3AuthNetwork: WEB3AUTH_NETWORK.MAINNET,
storage: window.localStorage,
manualSync: true, // This is the recommended approach
tssLib: tssLib
});

// Setup provider for EVM Chain
const evmProvider = new EthereumSigningProvider({ config: { chainConfig } });
evmProvider.setupProvider(makeEthereumSigner(coreKitInstance));
```

Check out the examples for your preferred blockchain and platform on our [examples page](https://web3auth.io/docs/examples).
Expand Down
46 changes: 25 additions & 21 deletions packages/providers/ethereum-provider/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,34 @@ npm install --save @web3auth/ethereum-provider
## 🩹 Example

```ts
import { CHAIN_NAMESPACES, WEB3AUTH_NETWORK } from "@web3auth/base";
import { EthereumPrivateKeyProvider } from "@web3auth/ethereum-provider";
import type { SafeEventEmitterProvider } from "@web3auth/base";
const signEthMessage = async (provider: SafeEventEmitterProvider): Promise<string> => {
const web3 = new Web3(provider as any);
const accounts = await web3.eth.getAccounts();
// hex message
const message = "0x47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad";
const signature = await web3.eth.sign(message, accounts[0]);
return signature;
import { Web3Auth, Web3AuthOptions } from "@web3auth/modal";
const clientId = "YOUR_WEB3AUTH_CLIENT_ID"; // get from https://dashboard.web3auth.io

const chainConfig = {
chainNamespace: CHAIN_NAMESPACES.EIP155,
chainId: "0xaa36a7",
rpcTarget: "https://rpc.ankr.com/eth_sepolia",
// Avoid using public rpcTarget in production.
// Use services like Infura, Quicknode etc
displayName: "Ethereum Sepolia Testnet",
blockExplorerUrl: "https://sepolia.etherscan.io",
ticker: "ETH",
tickerName: "Ethereum",
logo: "https://cryptologos.cc/logos/ethereum-eth-logo.png",
};

(async () => {
const provider = await EthereumPrivateKeyProvider.getProviderInstance({
chainConfig: {
rpcTarget: "https://polygon-rpc.com",
chainId: "0x89", // hex chain id
networkName: "matic",
ticker: "matic",
tickerName: "matic",
},
privKey: "4c0883a69102937d6231471b5dbb6204fe5129617082792ae468d01a3f362318",
});
const signedMessage = await signEthMessage(provider);
})();
const privateKeyProvider = new EthereumPrivateKeyProvider({
config: { chainConfig },
});

const web3AuthOptions: Web3AuthOptions = {
clientId,
web3AuthNetwork: WEB3AUTH_NETWORK.SAPPHIRE_MAINNET,
privateKeyProvider,
}
const web3auth = new Web3Auth(web3AuthOptions);
```

Check out the examples for your preferred blockchain and platform on our [examples page](https://web3auth.io/docs/examples).
Expand Down

0 comments on commit ba9ef6d

Please sign in to comment.