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.
yarn add @funded-labs/plug-mobile-sdk
As a secure exchange channel SDK uses WalletConnect, therefore you will have to create account and obtain Project ID from WalletConnect Cloud
- 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()
- 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)
}
- In order to esablish connection between dApp and Mobile app you need to pair.
if (!mobileProvider.isPaired()) {
mobileProvider.pair().catch(console.log)
}
When creating actor using SDK, identity delegation request will be performed.
ℹ️ 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.
Key | Type | Required | Notes |
---|---|---|---|
to | String | True | Principal or account ID |
amount | number | True | E8s |
subaccount | Uint8Array or number[] | False | |
fee | number | False | E8s |
Key | Type | Required | Notes |
---|---|---|---|
canisterId | String | True | |
standard | String | True | ICRC1, ICRC2, DIP20, DRC20 |
to | String | True | Principal |
amount | number | True | E8s |
subaccount | Uint8Array or number[] | False | |
fee | number | False | E8s |