Deeplinking Example
Exchanging Data Between Your Mobile App and Kukai-Embed
To communicate with Kukai-Embed, your mobile app (iOS/Android/Unity) needs to send and receive deeplinks to and from a self-hosted web page. This web page allows users to sign in with a social provider, submit operations, and receive responses with more information regarding their actions (e.g. operation hashes, errors).
Implement a web page that handles deeplinks:
- Clone our mobile app example repository
- Go to the
/web-clientfolder and runyarnto install the dependencies (install yarn if it’s not available):
cd web-client && yarn
- Change the redirect deeplink URL to match a schema recognized by your app (see line):
const REDIRECT_DEEPLINK = `${YOUR_PROJECT_SCHEMA}://`;
- Run the project locally to verify that it works with your mobile app by using
yarn dev(you can visithttp://localhost:3000for testing)
yarn dev
-
While
kukai-embedis running locally, send a deeplink from your mobile app to localhostwarningSimulators may not be able to access localhost. Use your private network address
http://<ip>:<port>orngrokif localhost is not available.-
For social login:
http://localhost:3000/?action=loginOnce users have successfully signed in using a social provider, kukai-embed will send a deeplink back to your mobile app (see line)
// send a deeplink that includes user information back to your mobile app
window.location.href = encodeURI(
`${REDIRECT_DEEPLINK}kukai-embed/?address=${pkh}&name=${name}&email=${email}&authResponse=${authResponse}&message=${message}&signature=${signature}&typeOfLogin=${userData.typeOfLogin}`
); -
For operations:
Send a deeplink from your mobile app to localhost, including the operation payload (stringified JSON) and optionally a
typeOfLoginthat was received from the previous deeplink. This will limit the social provider options, so that if users need to sign in again, they will only be presented with the social provider they initially selected:http://localhost:3000/?action=operation&typeOfLogin=<typeOfLogin>&operation=<payload>If the operation is injected successfully, kukai-embed will provide an
operationHash. Send a deeplink back to your app (see line)window.location.href = encodeURI(
`${REDIRECT_DEEPLINK}kukai-embed/?address=${pkh}&name=${name}&email=${email}&typeOfLogin=${typeOfLogin}&operationHash=${operationHash}`
); -
Handling errors:
In case of errors, operations will be rejected. Kukai-embed provides an
errorMessageas well as a low-levelerrorIdthat you can map to more user-friendly error messages. You may choose to handle errors on the web page itself, potentially attempting a retry, or send the errors back to your mobile app with a deeplink (see example):window.location.href = encodeURI(`${REDIRECT_DEEPLINK}kukai-embed/?errorMessage=${error?.errorMessage}&errorId=${error?.errorId}`)For more information regarding error handling, please visit the Error Handling page
-
-
Use
yarn buildto create a/buildfolder. You can upload this/buildfolder to a web hosting provider, such as Cloudflare Pages or Aws S3