Created
December 6, 2021 09:41
-
-
Save ezynda3/832a053e33e41cf178e801f09d042348 to your computer and use it in GitHub Desktop.
Web3Modal Svelte example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
import { onMount } from 'svelte' | |
import { defaultChainStore, web3 } from 'svelte-web3' | |
let Web3Modal | |
let WalletConnectProvider | |
onMount(() => { | |
Web3Modal = window.Web3Modal.default | |
WalletConnectProvider = window.WalletConnectProvider.default | |
}) | |
const enable = async () => { | |
let web3Modal = new Web3Modal({ | |
theme: 'dark', | |
cacheProvider: false, | |
providerOptions: { | |
walletconnect: { | |
package: WalletConnectProvider, | |
options: { | |
infuraId: '27e484dcd9e3efcfd25a83a78777cdf1' | |
} | |
} | |
}, | |
disableInjectedProvider: false | |
}) | |
const provider = await web3Modal.connect() | |
defaultChainStore.setProvider(provider) | |
} | |
</script> | |
{#if $web3.version} | |
<div class="buttons"> | |
<button class="btn btn-primary" on:click={enable}>Connect Wallet</button> | |
</div> | |
{/if} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment