Interacting with Wallets
Mini Apps can interact with a user's crypto wallet without needing to worry about popping open "select your wallet" dialogs or flakey connections.
A user minting an NFT using the Warpcast Wallet.
Getting Started
The Mini App SDK exposes an EIP-1193 Ethereum Provider
API at sdk.wallet.ethProvider
.
We recommend using Wagmi to connect to and interact with the users wallet. This is not required but provides high-level hooks for interacting with the wallet in a type-safe way.
Setup Wagmi
Use the Getting Started guide to setup Wagmi in your project.
Install the connector
Next we'll install a Wagmi connector that will be used to interact with the user's wallet:
npm install @farcaster/frame-wagmi-connector
Add to Wagmi configuration
Add the Mini App connector to your Wagmi config:
import { http, createConfig } from 'wagmi'
import { base } from 'wagmi/chains'
import { farcasterFrame as miniAppConnector } from '@farcaster/frame-wagmi-connector'
export const config = createConfig({
chains: [base],
transports: {
[base.id]: http(),
},
connectors: [
miniAppConnector()
]
})
Connect to the wallet
If a user already has a connected wallet the connector will automatically
connect to it (e.g. isConnected
will be true).
It's possible a user doesn't have a connected wallet so you should always check for a connection and prompt them to connect if they aren't already connected:
import { useAccount, useConnect } from 'wagmi'
function ConnectMenu() {
const { isConnected, address } = useAccount()
const { connect, connectors } = useConnect()
if (isConnected) {
return (
<>
<div>You're connected!
<div>Address: {address}</div>
</>
)
}
return (
<button
type="button"
onClick={() => connect({ connector: connectors[0] })}
>
Connect
</button>
)
}
Send a transaction
You're now ready to prompt the user to transact. They will be shown a preview of the transaction in their wallet and asked to confirm it:
Follow this guide from Wagmi on sending a transaction (note: skip step 1 since you're already connected to the user's wallet).
Troubleshooting
Transaction Scanning
Modern crypto wallets scan transactions and preview them to users to help protect users from scams. New contracts and applications can generate false positives in these systems. If your transaction is being reported as potentially malicious use this Blockaid Tool to verify your app with Blockaid.