Using Tableland SQL To Track Object Name, Type, and IPFS CID of Objects Stored in an Filebase Bucket

Tableland is an SQL database and network protocol built for use on the Ethereum network. Tableland can be used to store anything from tokenURI metadata to NFT extensions or DAO tools. Tables created and stored with Tableland utilize a user’s Ethereum wallet address for authentication, so no usernames, passwords, or access keys required.

Tableland can be used to record and track metadata for objects stored in a Filebase IPFS bucket. Objects stored on the IPFS network have an associated IPFS CID which is unique to each file, but isn’t easily identifiable like typical file IDs or storage paths are. To solve this, you can create a database with Tableland that tracks your objects and their associated file name, type, and IPFS CID so you can query it whenever you need to quickly reference an object.

Read below to learn how to use Tableland SQL to track object name, type, and IPFS CID of objects stored in an IPFS Filebase bucket.

Prerequisites:

  • Sign up for Tableland early access using their Quick Start instructions. This process involves having your Ethereum public wallet address whitelisted for use with the Tableland API.
  • Download and install the Tableland CLI tool: npm i -g @textile/tableland-cli
  • Have Your Filebase Access and Secret Keys. Learn how to view your access keys here.
  • Have a Filebase bucket created on the IPFS network. For instructions on how to create a bucket on the IPFS network, see here.

Once your ETH wallet address has been whitelisted for use with Tableland, you will need to grab your private key string to interact with Ethereum to create a new table.

You can follow these instructions to grab your private key string from Metamask.

Next, export your private key string as an environment variable so you don’t have to keep pasting it.

export TBL_PRIVATE_KEY=[PRIVATE_KEY_STRING]

Replace PRIVATE_KEY_STRING with your private key string.

Then, use the following CLI command to create a table on Tableland called AssetTracker.

tableland create "CREATE TABLE AssetTracker (id INT PRIMARY KEY, name TEXT, type TEXT, cid TEXT, provider TEXT, url TEXT);" --description="Filebase Asset Tracker"

The response from that query is your new table name! You’ll need to reference that later to update and query the table. It should look something like the following:

{ "name": "assettracker_192" }

If you have your own API keys for Infura, Alchemy, etc you can avoid the warning message that was printed with the above command. See tableland create —help for details.

Then, insert some data to query using the query CLI command:

tableland query "INSERT INTO assettracker_192 VALUES (0, 'filebase_robot.png', 'PNG', 'bafybeict7kegxaugjue5rcys65islddi2rnzmj2hh2wfq3wynf7t772hy4', 'filebase.com', 'https://bafybeict7kegxaugjue5rcys65islddi2rnzmj2hh2wfq3wynf7t772hy4.ipfs.dweb.link');"

Replace assettracker_192 with the value you received in the previous step. The following table has some additional objects you might want to include.

Example Database Table:

id name type cid provider url
1 filebase_robot.png PNG bafybeict7kegxaugjue5rcys65islddi2rnzmj2hh2wfq3wynf7t772hy4 https://filebase.com https://bafybeict7kegxaugjue5rcys65islddi2rnzmj2hh2wfq3wynf7t772hy4.ipfs.dweb.link
2 filebase_logo.png PNG bafkreighyv7jppuyen6kvdw3lhnleydibj44wej3ejq2j7ndwd3hsa7oam http://filebase.com https://bafkreighyv7jppuyen6kvdw3lhnleydibj44wej3ejq2j7ndwd3hsa7oam.ipfs.dweb.link

To query the database, use the following CLI command:

tableland query "SELECT * FROM assettracker_192;"

This example queries all entries in the database. You can modify this to reflect your desired query for a single object or a certain criteria of objects.

For more information on Tableland, check out their documentation here.

Resources

Experience the power of Web3 in seconds: Get started with 5GB of free object storage with no expirations and no trials.

Need more storage?  Use code "WEB3WELCOME" for 1TB of storage (your first month free) on us!

For more information on Tableland, check out their documentation here, and blog.

Filebase - Tableland Docs Section