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 useEmbeddedWallet hook.

tsx
import {useEmbeddedWallet, isConnected, needsRecovery} from '@privy-io/expo';

const Component = () => {
  const wallet = useEmbeddedWallet();
  const [password, setPassword] = useState('');

  const signMessage = (provider: EIP1193Provider) => {
    // 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]]
    });
  }

  if (isConnected(wallet)) {
    /* The user's embedded wallet exists and is ready to be used! */
    return <Button onPress={() => { signMessage(wallet.provider) }}>Sign a message</Button>
  }

  if (needsRecovery(wallet)) {
    /*
      The user's embedded wallet exists but has never been loaded on this device.
      They will need to go through the password recovery flow to use it.
    */
    return (
      <View>
        The user's embedded wallet exists but has never been loaded on this device. They will need
        to go through the password recovery flow to use it.
      </View>
    );
  }

  return null;
};

INFO

Users are only required to enter the password for their embedded wallet if both of the following are true:

The useEmbeddedWallet hook's status property helps inform your app whether these conditions are true for the current user's wallet, allowing you to prompt the user for their password only when necessary.