Skip to content

Mobile Auth

Plug Mobile SDK

Warning

This beta version of Plug Mobile auth is aimed toward the developers to have time to test how the integration works and make the (minor) changes needed to make it work with their dApps. We expect to find problems with the integration, if you are a user make sure to use the last mobile application version.

Introduction

Plug mobile SDK is a suite that allows you to have an authenticated session with you dApp within mobile device browser, request token transfers or approve.

Installation

yarn add @funded-labs/plug-mobile-sdk

Integrating Plug Mobile with your dApp

Important

Plug Mobile SDK requires mobile application with version >= 1.2.0

As a secure exchange channel SDK uses WalletConnect, therefore you will have to create account and obtain Project ID from WalletConnect Cloud

  1. Check that your dApp is running in mobile environment - for that we provide helper method
import { PlugMobileProvider } from '@funded-labs/plug-mobile-sdk'

const isMobile = PlugMobileProvider.isMobileBrowser()
  1. Initialize provider if running in mobile environment
if (isMobile) {
  const provider = new PlugMobileProvider({
    debug: true, // If you want to see debug logs in console
    walletConnectProjectId: '', // Project ID from WalletConnect console
    window: window,
  })
  provider.initialize().catch(console.log)
}
  1. In order to esablish connection between dApp and Mobile app you need to pair.
if (!mobileProvider.isPaired()) {
  mobileProvider.pair().catch(console.log)
}

Creating agent

When creating actor using SDK, identity delegation request will be performed.

Warning

Note that for security reasons Plug will restrict identity delegations to token and NFT canisters. Those canisters will be filtered out from the target array, when delegating identity

const createAgent = async () => {
  const agent = await mobileProvider.createAgent({
    host: 'https://icp0.io',
    targets: [], // List of canister you are planning to call
  })
  return agent
}

You can then use returned agent with delegated identity to create actors etc.

Mobile Provider available methods

Requesting ICP transfer

requestTransfer

Key Type Required Notes
to String True Principal or account ID
amount number True E8s
subaccount Uint8Array or number[] False
fee number False E8s

You're off to the races! 🐎 If you've gotten this far and are still stuck at any point or have feedback for us to that can help us to improve the user or developer experience, please reach out to us on Discord.