Skip to content

createWallet ​

The createWallet function initializes the embedded wallet and exposes web3 providers to the web page.

Example ​

ts
import { createWallet } from '@drop-wallet/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 own settings — allowed parent origins, feature flags, and per-dApp analytics scope.

INFO

This is only required for production. See the App ID guide for registration. You can omit it during local development; the wallet will load with a localhost-only allow-list.

walletUrl ​

Origin of the Drop wallet iframe. Defaults to https://www.dropwallet.app.

Only override this to point at a preview deployment or a local wallet instance — production dApps should always leave the default.

signerUrl ​

Origin of the Drop signer popup used for passkey flows. Defaults to the canonical signer. Same rules as walletUrl apply.

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 provider is returned.

Example
ts
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. If you want to disable this behavior, pass the eip6963 option.

Example
ts
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
ts
const wallet = createWallet({
  providers: {
    ethereum: {
      dangerouslyInjectWindow: true,
    },
  },
})

window.ethereum.request(/* ... */)

Solana ​

By default, a Phantom-like provider is returned.

Example
ts
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. If you want to disable this behavior, pass the walletStandard option.

Example
ts
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
ts
const wallet = createWallet({
  providers: {
    solana: {
      dangerouslyInjectWindow: true,
    },
  },
})

window.solana.connect()
Transaction versions ​

The wallet signs legacy, v0 and v1 Solana transactions. You choose the version by how you build the transaction, and the wallet signs exactly the bytes you pass it. solana.supportedTransactionVersions lists what the wallet accepts. v1 needs @drop-wallet/core 1.1.0 or later.

Use v1 when you need more room: a transaction can be up to 4,096 bytes instead of 1,232. Build it with @solana/kit 8 or later, and pass it to the wallet as serialized bytes.

Example
ts
import {
  address,
  appendTransactionMessageInstruction,
  compileTransaction,
  createTransactionMessage,
  getTransactionEncoder,
  pipe,
  setTransactionMessageComputeUnitLimit,
  setTransactionMessageFeePayer,
  setTransactionMessageLifetimeUsingBlockhash,
  setTransactionMessageLoadedAccountsDataSizeLimit,
} from '@solana/kit'

const solana = await wallet.getProvider('solana')
const { publicKey } = await solana.connect()

// `latestBlockhash` and `instruction` come from your app.
const message = pipe(
  createTransactionMessage({ version: 1 }),
  (m) => setTransactionMessageFeePayer(address(publicKey.toBase58()), m),
  (m) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, m),
  (m) => setTransactionMessageComputeUnitLimit(5_000, m),
  (m) => setTransactionMessageLoadedAccountsDataSizeLimit(64 * 1024, m),
  (m) => appendTransactionMessageInstruction(instruction, m),
)
const bytes = getTransactionEncoder().encode(compileTransaction(message))

const signed = await solana.signTransaction(bytes)

A few things differ from v0:

  • Set the limits yourself. A v1 transaction's compute unit and account data limits default to zero, so without them it fails. The approval screen warns the user, but can't fix it.
  • No lookup tables. Every account is listed in the transaction, up to 64.
  • Send it yourself. The embedded wallet signs but doesn't send, for any version. Send the signed bytes through your RPC with encoding: 'base64', and read the transaction back with maxSupportedTransactionVersion: 1.
  • Fetch the blockhash last. It lasts about 30 seconds, and the user has about 25 of them to approve.
Signing in to your backend ​

The wallet knows nothing about your backend's session. To start one, have your server issue a one-time message, sign it with solana.signMessage, and verify the signature on the server. Store the session together with the address that signed it.

Then check that address. The user can switch to another Drop account in the wallet, and a session that only names an account goes on showing the previous one. On every page load, read the connected address without opening the signer, and sign in again when it differs:

Example
ts
const solana = await wallet.getProvider('solana')

// Never opens the signer. Throws while the wallet is locked.
const connected = await solana
  .connect({ onlyIfTrusted: true })
  .then(({ publicKey }) => publicKey.toBase58())
  .catch(() => null)

// `session` is yours: the token and the address that signed for it.
if (session && connected && session.address !== connected) {
  clearSession()
  await signIn(connected)
}

A few things to keep in mind:

  • A lock is not a sign-out. The wallet locks itself when it sits idle, and the provider emits disconnect. Keep the session, and compare again once an address comes back.
  • Unlocking doesn't reconnect the provider. useConnected() turns true again, but the provider has no key until you call connect({ onlyIfTrusted: true }). Probe again after every unlock.
  • Don't wait for an event. The provider doesn't announce a switch to another account, so compare the address yourself.

Bitcoin ​

By default, a Sats Connect v1 provider is returned.

Example
ts
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. If you want to disable this behavior, pass the walletStandard option.

Example
ts
const wallet = createWallet({
  providers: {
    bitcoin: {
      walletStandard: false,
    },
  },
})

Universal ​

Drop ships with a universal provider that lets you use a single connect flow for a multi-chain dApp. It is recommended to interact with the provider via Wallet Standard. The universal provider registers itself with the name Drop Universal.

Example
ts
import { createWallet } from '@drop-wallet/core'

const wallet = createWallet({
  providers: {
    ethereum: true,
    solana: true,
    universal: true,
  },
})
tsx
import { useWallets, useConnect } from '@wallet-standard/react'
import { useMemo } from 'react'

const wallets = useWallets()
const universalWallet = useMemo(
  () => wallets.find(({ name }) => name === 'Drop 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.

INFO

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
ts
import { createWallet } from '@drop-wallet/core'

const wallet = createWallet({
  providers: {
    bitcoin: true,
    ethereum: true,
    solana: true,
    universal: true,
  },
})

const provider = await wallet.getProvider('universal')

/** Connect Bitcoin, Ethereum and Solana at the same time. */
const accounts = provider.connect()

Return value ​

createWallet returns a Wallet instance with the following methods:

getProvider(chain) ​

Returns a promise resolving to the web3 provider for the given chain ('bitcoin', 'ethereum', 'solana', or 'universal'). Resolves to null if the provider was not enabled in the providers config.

getSelectedChains() ​

Returns the chain-filter selection stored by the embedded wallet. This is the user's display preference and is separate from the providers configuration, which describes the chains your application supports.

subscribeSelectedChains(listener) ​

Calls listener with the current selected-chain snapshot and whenever the selection changes. Returns an unsubscribe function.

getLocale() ​

Returns the language currently selected in the embedded wallet.

subscribeLocale(listener) ​

Calls listener with the current wallet locale and whenever it changes. Returns an unsubscribe function.

setLocale(locale) ​

Asks the embedded wallet to persist and apply a language. Changes made this way follow the same local and account persistence path as the wallet UI.

getCurrency() ​

Returns the fiat display currency selected in the embedded wallet.

subscribeCurrency(listener) ​

Calls listener with the current display currency and whenever it changes. Returns an unsubscribe function.

setCurrency(currency) ​

Asks the embedded wallet to persist and apply a fiat display currency. Like locale changes, this uses the wallet's local and account persistence path.

configureAutoConfirmation() ​

Opens the wallet signer's authenticated auto-confirmation configuration flow. The signer retains ownership of the approval policy; it is not exposed to or stored by the host application.

renderWidget(element) ​

Attaches the wallet iframe to a specific DOM element so the user sees the wallet UI. Pass null to detach the iframe back to document.body. The React bindings handle this for you via <WalletWidget>.

setWidgetConfig(config) ​

Forwards a widget configuration (theme, size, shape, compact) to the embedded wallet. The React bindings handle this for you via <WalletWidget>.

disconnect() ​

Forwards a wallet:disconnect message to the iframe. Useful if you want to programmatically log the user out without waiting for them to click the in-widget disconnect button.