LinkLabs (ElizaOS+Functions)
  • Chainlink Workshop: Use AI agent to mint an NFT gift
    • Use an AI agent to interact with Blockchains
  • 1. Create table in Supabase
  • 2. Deploy the GetGift.sol
  • 3 Register A CL Functions Subscription
  • 4. Prepare DON hosted secrets
  • 5. Setup and start Eliza agent
  • 6. Use twitter client
Powered by GitBook
On this page
  • Where are we?
  • Why do we need to save data in traditional databases?
  • Steps to create table and insert records
Export as PDF

1. Create table in Supabase

PreviousUse an AI agent to interact with BlockchainsNext2. Deploy the GetGift.sol

Last updated 3 days ago

Where are we?

Why do we need to save data in traditional databases?

It is very common for Web3 projects to have a hybrid design. While assets are created, stored and transferred on blockchains, most business logic and application data run on Web2 infrastructure.

In this case, while NFTs gifts are minted and transferred on-chain, secret gift codes that are supposed to be shared with giftees are saved in a traditional database. After the request from users, the AI agent will check for user input gift codes with database records.

Now let's move on to managing data off-chain. In this step, we will use Supabase to store some crucial data, specifically the gift code consumed by users.

The Web2 infrastructure we are going to use is Supabase which provides a suite of tools to simplify the backend development process. We are going to use Supabase to create rapid backend services with its built-in PostgreSQL database.

Steps to create table and insert records

  1. Create a new organization

Complete configurations of the organization with free plan. You can name the organization with whatever name you like.

  1. Once the Organization and its project is created, go the table editor to create a new table called "Gifts" to save gift names and codes.

Note:

  1. The Table name "Gifts" is case sensitive - it will be important when you compose the URL to fetch from the database via the Supabase API.

  2. Keep the "Enable Row Level Security (RLS)" checked as default since the setting allow you to manage the row-level read and write access.

Table Columns

We need 3 columns in the Gifts table as follows:

  • ID: This will serve as the primary key for our table. It will be an integer type to uniquely identify each gift entry.

  • gift_name: A varchar type column to store the name of the gift. This can be used to display or describe the gift to the users.

  • gift_code: Also a varchar type, where we'll store the unique code associated with each gift. This code will be what users input on Twitter, which our smart contract will then verify against this stored data.

In the table, there is a auto-generated column "id" that is the primary key of the record. You need to create 2 other columns: second column "gift_name" that holds names of gifts in the table; third column "gift_code" for secret code thats will be shared to giftees.

  1. Insert records to the table

After the table is created, click on the green "SAVE" button.

The "Gifts" table will look like this:

id	gift_name	gift_code
1	1-month premium	Ce9OdVGMFdyr
2	50 discount	Nbbut8vlkKe9
3	100 discount	hTXcVopv1Wov

These values in gift_code must be identical to the above to match the variable we defined in GetGift.sol later.

Then in Supabase, in the Table Editor view, click the green INSERT button and choose "Import data from CSV" and then choose the CSV you just downloaded.

After records are uploaded and inserted, your table should look as below:

  1. Create RLS policy for the table

On the left navigator bar: go to "Authentication" >> "Policies". Under the table, click "Create policy".

On the right-panel "Template", choose the first "SELECT" policy template ("Enable Read Access For All Users") and click "save policy". By doing this, you have successfully created a RLS (Row Level Security) policy to allow users who have API key to read the table.

  1. Go the tab "project settings" on the left navigation bar (it has the ⚙️ icon) >> "Data API" to get project access URL and API key.

Note the URL and API key somewhere safe or just keep this tab open. You will need these in the next step.

Create a new organization at Supabase . Within an organization, you can have multiple projects.

Now we need to insert 3 rows into the table. For your convenience you can use . Export the data as csv (File >> Download>> CSV).

dashboard
this google sheet
Supabase dashboard
Create an organization
Create a new table with name "Gifts"
3 columns in the table
3 rows added to the table
Create Policy for table gifts
create a policy for read permission
URL and API Key for Anon