NEAR Protocol: Storing Off-Chain Data on IPFS using Filebase

Learn how to use Filebase for off-chain NEAR Protocol data storage on IPFS.

What is NEAR Protocol?

NEAR Protocol is a decentralized blockchain platform that enables developers to build decentralized applications with a focus on usability and scalability. It was designed to address some of the scalability and usability issues faced by other blockchain platforms.

Read below to learn how to use Filebase for off-chain NEAR Protocol data storage on IPFS. By storing data on IPFS, it can be referenced via NEAR Protocol smart contracts using the file or folder’s IPFS CID value.

Prerequisites:

1. To pin data to IPFS, you can use the Filebase Web Console Dashboard or S3-Compatible API.

This tutorial will showcase how to use Web Console Dashboard. For information on our S3-Compatible API, check out our documentation.

2. Start by clicking on the ‘Buckets’ option from the menu to open the Buckets dashboard.

3. Select your IPFS Bucket.

4. After clicking on the bucket name, you will see any previously uploaded files.

To upload another file, select 'Upload', then select 'File' from the options.

5. Select the file you want to upload to the IPFS.

6. Once uploaded, you will be able to view and copy the IPFS CID from the 'CID' category, as seen below.

Then, take note of the file’s CID to be used in your NEAR Protocol smart contract.

7. Next, clone the following NEAR Protocol NFT example repository:

git clone https://github.com/near-examples/NFT.git

8. Navigate inside this new director, then build the smart contract.

cd NFT

./scripts/build.sh

9. Next, deploy the smart contract for the NFT with the command. This command uses an auto-generated, testnet wallet:

near dev-deploy --wasmFile non_fungible_token.wasm

This command will return your testnet address.

10. To set this testnet address as a local environment variable, use the following command:

source neardev/dev-account.env

11. Then, use the following command to initialize the contract:

near call $CONTRACT_NAME new_default_meta '{"owner_id": "'$CONTRACT_NAME'"}' --accountId $CONTRACT_NAME

12. To mint your NFT, run the following command, changing the following fields to match your desired NFT configuration:

  • title: Your NFT’s Title.

  • description: Your NFT’s Description

  • CID: Your IPFS CID that you received when you uploaded your image to Filebase.

near call $ID nft_mint '{"token_id": "0", "receiver_id": "'$ID'", "token_metadata": { "title": "<TITLE>", "description": "<DESCRIPTION>", "media": "https://ipfs.filebase.io/ipfs/<CID>", "copies": 1}}' --accountId $ID --deposit 0.1

If you have any questions, please join our Discord server, or send us an email at hello@filebase.com

Last updated