Skip to main content

Storage

Get the instance of the ThirdwebStorage class being used by the ThirdwebProvider.

Allows you to use the TypeScript SDK functionality of Storage in your React native app.

API Key

You will require an API key to use thirdweb’s storage services with the SDK. If you haven’t created a key yet you can do so for free from the thirdweb dashboard.

You can then obtain a clientId from the API key which you will need to pass to the ThirdwebProvider component:

import { ThirdwebProvider } from "@thirdweb/react-native";

const App = () => {
return (
<ThirdwebProvider clientId="YOUR_CLIENT_ID">
<YourApp />
</ThirdwebProvider>
);
};

Please note that you will also need to get your app's bundleId and pass it in the Allowed Bundle IDs section when creating your API key. Check how you can get your app's bundleId.

useStorage hook

Configurable in the storageInterface prop of the ThirdwebProvider.

The hook returns a ThirdwebStorage instance. View the TypeScript Storage documentation for more information.

import { useStorage } from "@thirdweb/react-native";

Usage

import { useStorage } from "@thirdweb-dev/react-native";

export default function Component() {
const storage = useStorage();
...
// Now you can use the functionality of the ThirdwebStorage class:
const resp = await storage?.download("ipfs-url"); // Download a file from IPFS
if (resp.ok) {
const value = await resp?.json();
}

const fileIpfsHash = await storage?.upload({
name: 'file1',
type: 'file-mime-type',
uri: 'file-uri-on-device',
}); // Upload a file to IPFS
const objIpfsHash = await storage?.upload({key: 'value'}); // Upload an object to IPFS
const strIpfsHash = await storage?.upload('string-to-upload'); // Upload a string to IPFS
}