Skip to main content

Vue

Introduction​

AppKit has support for Wagmi, Ethers and @solana/web3.js on Solana. Choose one of these ethereum libraries or solana to get started.

Installation​

npm install @web3modal/wagmi @wagmi/core @wagmi/connectors viem

Don't have a project ID?

Head over to WalletConnect Cloud and create a new project now!

Get startedcloud illustration

Cloud Configuration​

Create a new project on WalletConnect Cloud at https://cloud.walletconnect.com and obtain a new project ID.

Implementation​

For a quick integration you can use defaultWagmiConfig function which wraps Wagmi's createConfig function with a predefined configuration. This includes WalletConnect, Coinbase and Injected connectors, and the Blockchain API as a transport

info

If you're using Nuxt, you can set wagmi's ssr option to true and call the reconnect function after your application mounts.

In your App.vue file set up the following configuration

<script setup>
import { createWeb3Modal, defaultWagmiConfig } from '@web3modal/wagmi/vue'

import { mainnet, arbitrum } from 'viem/chains'
import { reconnect } from '@wagmi/core'

// 1. Define constants
const projectId = 'YOUR_PROJECT_ID'

// 2. Create wagmiConfig
const metadata = {
name: 'AppKit',
description: 'AppKit Example',
url: 'https://web3modal.com', // origin must match your domain & subdomain
icons: ['https://avatars.githubusercontent.com/u/37784886']
}

const chains = [mainnet, arbitrum]
const config = defaultWagmiConfig({
chains,
projectId,
metadata,
...wagmiOptions // Optional - Override createConfig parameters
})

reconnect(config)
// 3. Create modal
createWeb3Modal({
wagmiConfig: config,
projectId,
enableAnalytics: true // Optional - defaults to your Cloud configuration
})
</script>

<template> // Rest of your app ... </template>

Trigger the modal​

To open AppKit you can use our web component or build your own button with AppKit composables. In this example we are going to use the <w3m-button> component.

Web components are global html elements that don't require importing.

<template>
<w3m-button />
</template>

Learn more about the AppKit web components here

Smart Contract Interaction​

Wagmi actions can help us interact with wallets and smart contracts:

<script setup lang="ts">
import { readContract } from '@wagmi/core'
import { USDTAbi } from '../abi/USDTAbi'

const USDTAddress = '0x...'

const data = readContract({
abi: USDTAbi,
address: USDTAddress,
functionName: 'symbol'
})
</script>

Read more about Wagmi actions for smart contract interaction here.