volo-sdk-react-native v0.5.2
volo-sdk-react-native
Volo SDK
Installation
yarn add volo-sdk-react-native
Usage
Follow the instructions here to setup deeplinking in your app. Note: for the correct work of the SDK you do not have to add Universal Links/Android App Links support.
Also you need to install react-native-get-random-values.
Import the SDK and call the init function in the root of your project (App.tsx).
import {voloSDK} from 'volo-sdk-react-native'
voloSDK.init({
deeplink: 'exampleapp://', // The deeplink your dapp can open (used to redirect back to the app from Volo Wallet)
appName: 'Example app', // The name of your dapp
appIcon: 'https://google.com', // The link to your dapp's icon
storage: {
getItem: (key) => SInfo.getItem(key, options),
setItem: (key, value) => SInfo.setItem(key, value, options),
deleteItem: async (key) => {
SInfo.deleteItem(key, options)
},
},
})
Storage argument takes three async functions to get, set, and delete item from device storage. You need to provide the implementation yourself using storage library of your choice (e.g. AsyncStorage
, MMKV
, sensitive-info
, etc.). This storage does not have to be secure, as we are not storing any sensitive info in it.
Now you can import and use functions and hooks.
Hooks
The SDK exposes the following hooks to connect to Volo Wallet:
Hook | Function | Arguments | Returns | Description |
---|---|---|---|---|
useConnect | connect | void | Promise<boolean> — whether the connection was accepted | Use this hook to connect to Volo Wallet and request the permissions |
useExecuteMoveCall | executeMoveCall | data: MoveCallTransaction | Promise<SuiExecuteTransactionResponse> — the result of the Move Call | Use this hook to execute move call |
useRequestPermissions | requestPermissions | void | Promise<boolean> — whether the connection was accepted | The same as connect |
useSignAndExecuteTransaction | signAndExecuteTransaction | transaction: UnserializedSignableTransaction | Promise<SuiExecuteTransactionResponse> — the result of Sign and Execute transaction | Use this hook to sign and execute a single transaction |
useSignAndExecuteMultipleTransactions | signAndExecuteMultipleTransactions | transactions: UnserializedSignableTransaction[] | Promise<SuiExecuteTransactionResponse[]> — the array the results of Sign and Execute transactions | The same as signAndExecuteTransaction , but works for multiple transactions |
import {Sui} from 'volo-sdk-react-native'
// In any component
// ...
const {
connect, // returns Promise
cancel, // You can cancel the listener and the promise by calling this
} = Sui.useConnect()
Errors
This is a list of errors functions from hooks can throw.
import {
CancelledError,
ExternalError,
InvalidUrlError,
OpeningWalletDeeplinkError,
SDKNotInitiatedError,
} from 'volo-sdk-react-native'
Error name | Description |
---|---|
CancelledError | This error is thrown if you call cancel function |
ExternalError | This error is thrown if there's an error in Volo Wallet. It contains a message with more details |
InvalidUrlError | This error is thrown if the parsing of redirect URL failed (either JSON.parse , or some mandatory parameter is missing) |
OpeningWalletDeeplinkError | This error is thrown if Linking.canOpenURL returns false for the link to Volo Wallet |
SDKNotInitiatedError | This error is thrown if the SDK has not been initiated before calling the function |
Functions
import {Sui} from 'volo-sdk-react-native'
const {
getBalance,
signMessage,
verifyMessage,
hasPermissions,
getAccounts,
disconnect,
} = Sui
Function | Arguments | Returns | Description |
---|---|---|---|
signMessage | secretKey: Uint8Array, message: string | string | Sign a message with the given secret key |
verifyMessage | message: Hex, signature: Hex, publicKey: Hex | boolean | Verify that the given message hash corresponds to the signature and the public key |
hasPermissions | void | Promise<boolean> | After you first call connect and until you call disconnect, this function will return true. Otherwise — false. |
getAccounts | void | Promise<string[]> | After the successful connection and after every call of the hook that redirects to Volo Wallet and back to your app, an array of user's addresses is passed and saved. This function returns this array of addresses |
disconnect | void | Promise<void> | Reset the saved addresses and the connection |
getBalance | address?: string | Promise<{tokensBalance: SuiTokenDisplayObject[]; nfts: NFT[]}> | Fetch the balance for the given address on the Sui network. If the address is not provided, empty arrays will be returned |
For the getBalance
function, the SDK provides a hook that refetches the balance every 5000 ms:
import {Sui} from 'volo-sdk-react-native'
// In any component
// ...
const {
balance: SuiTokenDisplayObject[];
nft: NFT[];
isLoading: boolean;
error: unknown;
} = Sui.useBalanceSynced(address)
If the address is not provided (or it is undefined
), empty arrays for nfts and balance will be returned.
Made with create-react-native-library