createWallet
The createWallet
function initializes the embedded wallet and exposes web3 providers to the web page.
Example
import { createWallet } from '@passkeys/core';
const wallet = createWallet({
appId: '<YOUR_APP_ID>',
providers: {
bitcoin: true,
ethereum: true,
solana: true,
},
});
const ethereumProvider = await wallet.getProvider('ethereum');
ethereumProvider.request(/* ... */);
Reference
appId
Identifier of your application. This allows your integration to have its unique settings.
This is only required for production. Reach out to us at [email protected] to obtain yours.
providers
List of web3 providers you want to expose to your dApp, with their optional configuration.
Ethereum & EVM-Compatible Chains
By default, an EIP-1193 (opens in a new tab) provider is returned.
Example
const wallet = createWallet({
providers: {
ethereum: true,
},
});
const ethereumProvider = await wallet.getProvider('ethereum');
ethereumProvider.request(/* ... */);
Additionally, the provider is announced to the web page following EIP-6963 (opens in a new tab). If you want to disable this behavior, pass the eip6963
option.
Example
const wallet = createWallet({
providers: {
ethereum: {
eip6963: false,
},
},
});
If your dApp expects the provider to be available at window.ethereum
, you can also inject it there by passing the dangerouslyInjectWindow
option.
Example
const wallet = createWallet({
providers: {
ethereum: {
dangerouslyInjectWindow: true,
},
},
});
window.ethereum.request(/* ... */);
Solana
By default, a Phantom-like (opens in a new tab) provider is returned.
Example
const wallet = createWallet({
providers: {
solana: true,
},
});
const solanaProvider = await wallet.getProvider('solana');
solanaProvider.connect();
Additionally, the provider is announced to the web page following Wallet Standard (opens in a new tab). If you want to disable this behavior, pass the walletStandard
option.
Example
const wallet = createWallet({
providers: {
solana: {
walletStandard: false,
},
},
});
If your dApp expects the provider to be available at window.solana
, you can also inject it there by passing the dangerouslyInjectWindow
option.
Example
const wallet = createWallet({
providers: {
solana: {
dangerouslyInjectWindow: true,
},
},
});
window.solana.connect();
Bitcoin
By default, a Sats Connect v1 (opens in a new tab) provider is returned.
Example
const wallet = createWallet({
providers: {
bitcoin: true,
},
});
const bitcoinProvider = await wallet.getProvider('bitcoin');
bitcoinProvider.connect(/* ... */);
Additionally, the provider is announced to the web page following Wallet Standard (opens in a new tab). If you want to disable this behavior, pass the walletStandard
option.
Example
const wallet = createWallet({
providers: {
bitcoin: {
walletStandard: false,
},
},
});
If your dApp expects the provider to be available at window.BitcoinProvider
, you can also inject it there by passing the dangerouslyInjectWindow
option.
Example
const wallet = createWallet({
providers: {
bitcoin: {
dangerouslyInjectWindow: true,
},
},
});
window.BitcoinProvider.connect(/* ... */);
Universal
Passkeys comes with a universal provider that allows you to use a single connect for your multi-chain dApp.
It is recommended to interact with the provider via Wallet Standard (opens in a new tab).
The universal provider registers itself with the name Passkeys Universal
.
Example
import { createWallet } from '@passkeys/core';
const wallet = createWallet({
providers: {
ethereum: true,
solana: true,
universal: true,
},
});
import { useWallets, useConnect } from '@wallet-standard/react';
import { useMemo } from 'react';
const wallets = useWallets();
const universalWallet = useMemo(
() => wallets.find(({ name }) => name === 'Passkeys Universal'),
[wallets],
);
const [connecting, connect] = useConnect(universalWallet);
/** Connect Ethereum and Solana at the same time. */
const accounts = connect();
Once the universal provider is connected, you can use the other providers as you are used to.
The universal provider will only connect other providers that are also enabled in the config.
Additionally, the provider is accessible from the wallet instance.
Example
import { createWallet } from '@passkeys/core';
const wallet = createWallet({
providers: {
bitcoin: true,
ethereum: true,
solana: true,
universal: true,
},
});
const provider = wallet.getProvider('universal');
/** Connect Bitcoin, Ethereum and Solana at the same time. */
const accounts = provider.connect();