Skip to content

Getting an EIP-1193 Provider

To enable your app to request signatures and transactions from the embedded wallet, Privy embedded wallets export an EIP-1193 provider. This allows you request signatures and transactions from the wallet via a familiar JSON-RPC API (e.g. personal_sign).

To get an EIP-1193 provider for the embedded wallet, use the Privy Expo SDK's useEmbeddedEthereumWallet hook.

tsx
import {useEmbeddedEthereumWallet} from '@privy-io/expo';

const Component = () => {
  const {wallets} = useEmbeddedEthereumWallet();

  if (wallets.length === 0) {
    // The user has no embedded ethereum wallets
    return null;
  }

  // We are using the first (HD index 0) wallet here,
  // but you can use a different one depending on your use case.
  const wallet = wallets[0];

  const signMessage = async () => {
    const provider: EIP1193Provider = await wallet.getProvider();

    // Get the wallet address
    const accounts = await provider.request({
      method: 'eth_requestAccounts',
    });

    // Sign message
    const message = 'I hereby vote for foobar';
    const signature = await provider.request({
      method: 'personal_sign',
      params: [message, accounts[0]],
    });
  };

  return <Button onPress={signMessage}>Sign a message</Button>;
};

INFO

If you have opted into user-owned recovery then getting the EIP-1193 Provider might require performing the recovery flow.

Take a look at our recovery guide here for details!