Import, instantiate, and use the SDK by adding something similar to the following to your project script:
import PoolsSDK from '@pools/sdk';
import { Linking } from 'react-native';
import BackgroundTimer from 'react-native-background-timer';
const PSDK = new PoolsSDK({
openDeeplink: (link) => {
Linking.openURL(link); // Use React Native Linking method or another way of opening deeplinks.
},
timer: BackgroundTimer, // To keep the dapp alive once it goes to background.
dappMetadata: {
name: 'My dapp', // The name of your dapp.
url: 'https://mydapp.com', // The URL of your website.
},
});
const ethereum = PSDK.getProvider();
const accounts = await ethereum.request({ method: 'eth_requestAccounts' });
You can configure the SDK using any options and call any provider API methods. Always call eth_requestAccounts using ethereum.request(args) first, since it prompts the installation or connection popup to appear.
You can use EthersJS with your React Native app:
const provider = new ethers.providers.Web3Provider(ethereum);
// Get the balance of an account (by address or ENS name, if supported by network).
const balance = await provider.getBalance(ethereum.selectedAddress);
// Often you need to format the output to something more user-friendly,
// such as in ether (instead of wei).
const balanceInETH = ethers.utils.formatEther(balance);
// '0.182826475815887608'