# volo-sdk-react-native

> test

Latest version **0.5.2** (published 2023-01-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install volo-sdk-react-native
pnpm add volo-sdk-react-native
yarn add volo-sdk-react-native
bun add volo-sdk-react-native
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.5.2 |
| Published | 2023-01-19 |
| First published | 2022-12-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >= 16.0.0 |
| Dependencies | 9 |
| Unpacked size | 259.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Fancy Studios |
| Maintainers | victoriafancystudios |
| Keywords | react-native, ios, android |

## Links

- npm: https://www.npmjs.com/package/volo-sdk-react-native
- npm.io page: https://npm.io/package/volo-sdk-react-native

## Dependencies (9)

- [tweetnacl](https://npm.io/package/tweetnacl.md) ^1.0.3
- [url-parse](https://npm.io/package/url-parse.md) ^1.5.10
- [@noble/hashes](https://npm.io/package/@noble/hashes.md) ^1.1.3
- [patch-package](https://npm.io/package/patch-package.md) ^6.5.0
- [@mysten/sui.js](https://npm.io/package/@mysten/sui.js.md) 0.0.0-experimental-20221103194143
- [@noble/secp256k1](https://npm.io/package/@noble/secp256k1.md) ^1.7.0
- [text-encoding-shim](https://npm.io/package/text-encoding-shim.md) ^1.0.5
- [react-native-url-polyfill](https://npm.io/package/react-native-url-polyfill.md) ^1.3.0
- [react-native-get-random-values](https://npm.io/package/react-native-get-random-values.md) ^1.8.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 0.5.2 (latest) — 2023-01-19
- 0.5.1 — 2023-01-19
- 0.5.0 — 2023-01-19
- 0.4.2 — 2023-01-17
- 0.4.1 — 2023-01-17
- 0.4.0 — 2023-01-17
- 0.3.0 — 2023-01-17
- 0.2.2 — 2022-12-30
- 0.2.0 — 2022-12-30

## README

# volo-sdk-react-native

Volo SDK

## Installation

```sh
yarn add volo-sdk-react-native
```

## Usage

Follow the instructions [here](https://reactnavigation.org/docs/deep-linking/#testing-with-npx-uri-scheme) 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](https://www.npmjs.com/package/react-native-get-random-values).

Import the SDK and call the init function in the root of your project (App.tsx).

```ts
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 |

```ts
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.

```ts
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

```ts
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:

```ts
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](https://github.com/callstack/react-native-builder-bob)

---
_Source: https://npm.io/package/volo-sdk-react-native · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
