How to mock connector with @wagmi/core v2 #3420
-
Versions: "@wagmi/core": "^2.0.2",
"viem": "^2.0.5" Wagmi config file: import { createConfig, http, fallback, mock } from '@wagmi/core'
// import { mock } from '@wagmi/connectors'
// import { createClient, type Chain, custom } from 'viem'
import { polygonMumbai } from '@wagmi/core/chains'
export const web3Config = createConfig({
multiInjectedProviderDiscovery: true,
chains: [polygonMumbai],
connectors: [
mock({
accounts: ['0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266'],
features: { signMessageError: false }
})
],
transports: {
[polygonMumbai.id]: fallback([http(), http('https://rpc-mumbai.maticvigil.com')])
}
}) App.vue: <script setup lang="ts">
import { connect, disconnect, signMessage, type Connector } from '@wagmi/core'
import { web3Config } from './web3/web3Config'
async function con(connector: Connector) {
const { accounts, chainId } = await connect(web3Config, { connector })
console.log(accounts, chainId)
const signature = await signMessage(web3Config, { message: 'test' })
console.log(signature)
}
</script>
<template>
<div>
<button
v-for="connector in web3Config.connectors.filter((c) => c.type === 'mock')"
:key="connector.id"
@click="con(connector)"
>
login
</button>
</div>
</template> Doc page: https://wagmi.sh/react/api/connectors/mock Questions:connection is successful but
At the same time network request to
ScreenshotUpdateLooks like Mock can be implemented with |
Beta Was this translation helpful? Give feedback.
Answered by
giraffecrackers
Jan 12, 2024
Replies: 1 comment
-
Mock can be implemented with createConnector function. createConnector((config) => ({
// setup(){}, connect(){}, disconnect(){} ...
}) |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
giraffecrackers
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Mock can be implemented with createConnector function.