πŸ—οΈSetting Up the CLI

The steps below will walk you through installing the js implementation of CO2.Storage, setting up your environment variables, and testing everything. You'll then be able to use CO2.Storage to search, load, create and sign assets and templates in your javascript projects.

This assumes you have git and node-js installed. The tutorial was developed on macOS using the Terminal.

Installing CO2.Storage

1) Download the repo by running:

git clone https://github.com/protocol/co2-storage.git

2) Navigate to the cli folder:

cd co2-storage
cd cli

3) Install dependencies:

npm install

For reference, see the npm package co2-storage/js-api

Set Up Environment Variables

4) In co2-storage/cli, you should find a file named .env.example. Copy it, and rename to .env

We're going to use the .env file to store private keys. If handled properly, this will not expose your keys. The .env file is included in .gitignore, which will prevent it from being uploaded to git. If you want to check how the private keys are used, examine the function authenticateWithPK in Auth.js. If this is unfamiliar to you, use test accounts.

5) You should have a file that looks like this image. We're going to fill in the private keys necessary to use co2.storage.

6) Get "PK" from Metamask. In the browser plugin, go to menu > Account details > Export Private Key. Metamask will ask you for your account password. Copy the Metamask private key into PK in the .env file.

If your private key doesn't start with '0x' then append this at the beginning. This was not required with previous package versions, but is now (Q3 2023).

7) Get ESTUARY_API_KEY and FG_TOKEN from co2.storage. Log in to co2.storage with the same Metamask account you just got PK from. Click on the green button in the upper right hand corner, which should be labeled with your walled address 0x...

This will take you to a page with two different tokens. Use "My API token" as FG_TOKEN and "My Estuary Key" as ESTUARY_API_KEY.

The Estuary key should start with "EST" and end with "ARY" because the Estuary engineering team is clever.

8) Almost done! For the last key, you need an Infura account. Go to infura.io and log in or make a new account.

Go to Dashboard > API Keys. Click on the name of your account, which in the image below is CO2_storage_test. Copy the key to INFURA_API_KEY.

9) Check the keys in your .env file. All four should have different formats. If two of the keys look the same, you probably had a problem copy pasting. It happens. Save the file.

Try Out Examples

Test out some of the example scripts in co2-storage/cli/src/examples to make sure that your environment is set up properly and see how to use the js api!

There are two ways of using the js-api: either with your own IPFS node, or with the IPFS node provided by co2.storage. In step 10, we assume you haven't set up your own IPFS node and tell the example scripts to use the co2.storage node. If you do want to run your own IPFS node, see Configuring IPFS Nodes.

10) To run search_templates using the co2.storage ipfs node, first open search_templates.js in the examples folder. Comment out lines 5 and 6, which tell the script to use local addresses for the IPFS node and for the FG API. Then un-comment lines 7-8, which will tell the script to use the co2.storage node.

The lines should look like this:

// const ipfsNodeAddr = "/ip4/127.0.0.1/tcp/5001"
// const fgApiUrl = "http://localhost:3020"
const ipfsNodeAddr = "/dns4/web1.co2.storage/tcp/5002/https"
const fgApiUrl = "https://web1.co2.storage"

11) Going back to the command line, make sure you're in the folder co2-storage/cli. Then run:

npm run search_templates

Within a few seconds, this should give you a list of templates available on the 'sandbox' chain πŸŽ‰

12) To run other scripts in the examples folder, you'll have to configure each one to use the co2.storage IPFS node or use your own node. If you've done this and set up the .env file correctly, you should be able to run all of the scripts.

Scripts like add_asset and add_template require authentication, because co2-storage tracks who added what information using the index chain. Scripts that are read only, like search_templates and get_asset, do not require authentication so you should be able to use them without setting up the .env file as above.

Last updated