This guide will walk you through setting up Veramo on React Native. You should have a good understanding of React Native and have your environment set up correctly to build iOS and Android apps. Check out the React Native docs to learn more.
Let's setup Veramo to run locally on the device and use sqlite to store data, identities, and keys. Our identity provider will be ethr-did. Initially, we will set up the agent in the most basic config and add more plugins for additional functionality as we go. Right now we just want to create an identifer.
Install a TextEncoder polyfill and this will also trigger the postinstall script to install additional dependencies based on the rn-nodeify command to your app.
The latest version of TypeOrm breaks in React Native. To get around this you need to install the lastest working version v0.2.24. See more about this issue here
yarnadd typeorm@0.2.24
Add a resolutions key to your package.json file:
"resolutions:"{
"typeorm":"0.2.24"
}
Close the react native packager, clean the project, and rerun your app. If everything is okay, you should see the default React Native screen as before.
We bootstrap Veramo by creating a setup file and initializing the agent. Create a setup file in src/veramo/setup.ts and import the following dependencies:
Now that the agent has been created and configured with plugins, we can create some identifiers. For this, we will need some basic UI.
note
Veramo does not impose decisions on how you manage state in your app and will work alongside any existing architecture like Redux or Mobx etc. For brevity, we use useState in this example, but you can treat Veramo like you would any async data source.
Open App.tsx and delete all the contents and add the following code: