Skip to content

Instantly share code, notes, and snippets.

@ezynda3
Created December 6, 2021 09:41
Show Gist options
  • Save ezynda3/832a053e33e41cf178e801f09d042348 to your computer and use it in GitHub Desktop.
Save ezynda3/832a053e33e41cf178e801f09d042348 to your computer and use it in GitHub Desktop.
Web3Modal Svelte example
<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