React native - expo

When adding support make sure you have a native android codebase. You can have one created by running npx expo run:android in your codebase.

After that, install the expo-walletsdk using npm install --save expo-walletsdk

Right after installing you might need to do a rebuild, because it has some native code that needs to be compiled.

In the code you need to first import all the necessary functions by adding import * as ExpoWalletsdk from 'expo-walletsdk';

Sending a transaction

Then, let’s say you have a function where you send a tx, you can simply add an if which checks if the system-wallet is present, and if yes then run it through the walletsdk. Something like this:

if (ExpoWalletsdk.hasSystemWallet()){
  const transaction = {
    to: '0x3a4e6eD8B0F02BFBfaA3C6506Af2DB939eA5798c', // Receipient
    value: '10', // Value in wei
		chainId: 10, 
    chainRPCUrl: 'https://mainnet.optimism.io'
  };
  var txHash = ExpoWalletsdk.sendTransaction(transaction);
  console.log(txHash)
} else {
  console.log("No system wallet found")
}

Essentially, to and value is all you need to make a transaction, though it’s recommended to add a specific chainId and chainRPCUrl to make sure you are on the correct network. The sdk will automatically change chain to the one you specific and will broadcast the tx to the node that you specified. If you are making a tx to a contract, make sure to add a data field.

Signing a message

Same principle with sending a tx also applies to signing a message, you first check if the system-wallet is present and then make the request.

if (ExpoWalletsdk.hasSystemWallet()){
  const message = {
    message: "Hello World",
		type: "personal_sign" // Default is personal_sign
  };
  var signature = ExpoWalletsdk.signMessage(message);
  console.log(signature)
} else {
  console.log("No system wallet found")
}

By default the signMessage function will use personal_sign to sign a given message in this format. If your message is in hex format, you can define a type personal_sign_hex. And if you are signing typed data, you need to provide the json string in the message field and as type you need to write eth_signTypedData.

If there are any other questions please feel free to reach out in our discord, or message me on telegram at @mhaas_eth