0.1.3 • Published 1 year ago

@funded-labs/plug-mobile-sdk v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

npm.io

Plug Mobile SDK

Introduction

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

Installation

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

Integrating Plug Mobile with your dApp

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 provider 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.

:information_source: 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

KeyTypeRequiredNotes
toStringTruePrincipal or account ID
amountnumberTrueE8s
subaccountUint8Array or number[]False
feenumberFalseE8s

Requesting Token transfer

requestTokenTransfer

KeyTypeRequiredNotes
canisterIdStringTrue
standardStringTrueICRC1, ICRC2, DIP20, DRC20
toStringTruePrincipal
amountnumberTrueE8s
subaccountUint8Array or number[]False
feenumberFalseE8s