diff --git a/docs/src/lib/components/examples/ConnectWallet.svelte b/docs/src/lib/components/examples/ConnectWallet.svelte deleted file mode 100644 index 55d8fcd07..000000000 --- a/docs/src/lib/components/examples/ConnectWallet.svelte +++ /dev/null @@ -1,104 +0,0 @@ - - -
- {#if $wallets$?.[0]?.provider} -
-
- {#if account?.ens?.avatar?.url} - - {:else} -
- {/if} -
-
-
- {account?.ens ? `${account?.ens?.name} (${account?.address})` : `${account?.address}`} -
-
Connected to {$wallets$?.[0]?.label}
-
- - -
- {:else} - - {/if} -
diff --git a/docs/src/lib/components/examples/ReactConnectWallet.md b/docs/src/lib/components/examples/ReactConnectWallet.md deleted file mode 100644 index 12d9161fb..000000000 --- a/docs/src/lib/components/examples/ReactConnectWallet.md +++ /dev/null @@ -1,143 +0,0 @@ - -## Step 1: Import + Configure - -Import the libraries and any wallets you would like to use. For this example, we are going to use the injected wallets module. You can easily add more wallet support to your dapp via our other wallet modules. Additionally, we'll setup web3-onboard to support 2 chains: Ethereum mainnet and Polygon mainnet. - -```js title="App.tsx"|copy -import { Web3OnboardProvider, init } from '@web3-onboard/react' -import injectedModule from '@web3-onboard/injected-wallets' - -const INFURA_KEY = '' - -const ethereumRopsten = { - id: '0x3', - token: 'rETH', - label: 'Ethereum Ropsten', - rpcUrl: `https://ropsten.infura.io/v3/${INFURA_KEY}` -} - -const polygonMainnet = { - id: '0x89', - token: 'MATIC', - label: 'Polygon', - rpcUrl: 'https://matic-mainnet.chainstacklabs.com' -} - -const chains = [ethereumRopsten, polygonMainnet] - -const wallets = [injectedModule()] - -const appMetadata = { - name: 'Connect Wallet Example', - icon: 'My App Icon', - description: 'Example showcasing how to connect a wallet.', - recommendedInjectedWallets: [ - { name: 'MetaMask', url: 'https://metamask.io' }, - { name: 'Coinbase', url: 'https://wallet.coinbase.com/' } - ] -} - -const web3Onboard = init({ - wallets, - chains - appMetadata -}) - -function App() { - return ( - - - - ) -} - -export default MyApp -``` - -## Step 2: Display the connect wallet button - -In another file we'll create the component that will display our connect wallet button. We'll be using the `useConnectWallet` hook in order to achieve this. - -```js title="ConnectWallet.tsx"|copy -import { useEffect } from 'react' -import { useConnectWallet } from '@web3-onboard/react' -import { ethers } from 'ethers' - -export default function ConnectWallet() { - const [{ wallet, connecting }, connect, disconnect] = useConnectWallet() - const [ethersProvider, setProvider] = useState() - - useEffect(() => { - // If the wallet has a provider than the wallet is connected - if (wallet?.provider) { - setProvider(new ethers.providers.Web3Provider(wallet.provider, 'any')) - } - }, [wallet]) - - return ( -
- -
- ) -} -``` - -## Step 3: Display account information - -Now that we have our wallet connected, let's display some basic information, such as the connected wallet's address, ENS name, and avatar. - -```js title="ConnectWallet.tsx"|copy{8,10-19,28-37} -import { useEffect } from 'react' -import { useConnectWallet } from '@web3-onboard/react' -import { ethers } from 'ethers' - -export default function ConnectWallet() { - const [{ wallet, connecting }, connect, disconnect] = useConnectWallet() - const [ethersProvider, setProvider] = useState() - const [account, setAccount] = useState(null) - - useEffect(() => { - if (wallet?.provider) { - const { name, avatar } = wallet?.accounts[0].ens ?? {} - setAccount({ - address: wallet.accounts[0].address, - balance: wallet.accounts[0].balance, - ens: { name, avatar: avatar?.url } - }) - } - }, [wallet]) - - useEffect(() => { - // If the wallet has a provider than the wallet is connected - if (wallet?.provider) { - setProvider(new ethers.providers.Web3Provider(wallet.provider, 'any')) - } - }, [wallet]) - - if(wallet?.provider) { - return ( -
- ENS Avatar -
{ ens?.name ? ens.name : address }
-
Connected to {wallet.label}
- -
- ) - } - - return ( -
- -
- ) -} -``` - diff --git a/docs/src/lib/components/examples/SvelteConnectWallet.md b/docs/src/lib/components/examples/SvelteConnectWallet.md deleted file mode 100644 index 6e1a07fd1..000000000 --- a/docs/src/lib/components/examples/SvelteConnectWallet.md +++ /dev/null @@ -1,110 +0,0 @@ -## Step 1: Import + Configure - -Import the libraries and any wallets you would like to use. For this example, we are going to use the injected wallets module. You can easily add more wallet support to your dapp via our other wallet modules. Additionally, we'll setup web3-onboard to support 2 chains: Ethereum mainnet and Polygon mainnet. - -```js title="onboard.js"|copy -import Onboard from '@web3-onboard/core' -import injectedModule from '@web3-onboard/injected-wallets' - -const INFURA_KEY = '' - -const wallets = [injectedModule()] - -const chains = [ - { - id: '0x1', - token: 'ETH', - label: 'Ethereum Mainnet', - rpcUrl: `https://mainnet.infura.io/v3/${INFURA_ID}` - }, - { - id: '0x89', - token: 'MATIC', - label: 'Polygon', - rpcUrl: 'https://matic-mainnet.chainstacklabs.com' - } -] - -const appMetadata = { - name: 'Connect Wallet Example', - icon: 'My App Icon', - description: 'Example showcasing how to connect a wallet.', - recommendedInjectedWallets: [ - { name: 'MetaMask', url: 'https://metamask.io' }, - { name: 'Coinbase', url: 'https://wallet.coinbase.com/' } - ] -} - -const onboard = Onboard({ - wallets, - chains, - appMetadata, -}) - -export default onboard -``` - -## Step 2: Display the connect wallet button - -In main `App.svelte` file we'll import our previously initialized web3-onboard instance and then display our connect wallet button. - -```svelte title="App.svelte"|copy - - -
- -
-``` - -## Step 3: Display account information - -Now that we have our wallet connected, let's display some basic information, such as the connected wallet's address, ENS name, and avatar. - -```svelte title="App.svelte"|copy - - -{#if $wallets$?.[0]?.provider} -
- ENS Avatar -
{ ens?.name ? ens.name : address }
-
Connected to {wallet.label}
- -
-{:else} -
- -
-{/if} -```