How to generate a wallet connect uri #2129
-
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
@hernan-clich This can be a bit tricky, but it's possible. First add import { createConfig, http } from 'wagmi';
import { mainnet } from 'wagmi/chains';
import { walletConnect } from 'wagmi/connectors';
const config = createConfig({
connectors: [
walletConnect({
projectId: 'YOUR_PROJECT_ID',
showQrModal: false,
}),
],
chains: [mainnet],
transports: {
[mainnet.id]: http(),
},
}); Then you can create a component that gets the WalletConnect URI ( import { Connector, useConnect } from 'wagmi';
export function WalletConnectUri() {
const { connect, connectors } = useConnect();
// Get WalletConnect connector
const walletConnectConnector = connectors.find(
({ id }) => id === 'walletConnect'
);
const listenForWalletConnectUri = async (
walletConnectConnector: Connector
) => {
const provider = await walletConnectConnector.getProvider();
// @ts-expect-error
provider.once('display_uri', (uri) => {
console.log('WalletConnect URI:', uri);
});
};
return (
<button
onClick={() => {
if (!walletConnectConnector) {
throw new Error('WalletConnect connector not found');
}
listenForWalletConnectUri(walletConnectConnector);
connect({ connector: walletConnectConnector });
}}
>
Get WalletConnect URI
</button>
);
} Basically you get the WalletConnect connector from wagmi, get the provider and listen for emit message ( Regarding if we can export Let me know if that's helpful! |
Beta Was this translation helpful? Give feedback.
@hernan-clich This can be a bit tricky, but it's possible.
First add
walletConnect
connector to yourcreateConfig
like this:Then you can create a component that gets the WalletConnect URI (
WalletConnectUri.tsx
):