codex-testnet-starter/USINGCODEX.md

6.1 KiB

Using Codex

Codex's web-API is documented: Here This document will show you several useful API calls.

Overview

  1. Debug
  2. Upload a file
  3. Download a file
  4. Local data
  5. Create storage availability
  6. Purchase storage
  7. View purchase status

Debug

An easy way to check that your node is up and running is:

curl http://localhost:8080/api/codex/v1/debug/info \
  --write-out '\n'

This will return a JSON structure with plenty of information about your local node. It contains peer information that may be useful when troubleshooting connection issues.

Upload a file

Warning Once you upload a file to Codex, other nodes in the testnet can download it. Please do not upload anything you don't want others to access, or, properly encrypt your data first.

curl --request POST \
  http://localhost:8080/api/codex/v1/data \
  --header 'Content-Type: application/json' \
  --write-out '\n' \
  -T <FILE>

On successful upload, you'll receive a CID. This can be used to download the file from any node in the network.

📢 Hint

Are you on the Codex Discord server? Post your CID in the testnet channel, see if others are able to download it. Codex does not (yet?) provide file metadata, so if you want others to be able to open your file, tell them which extension to give it.

Download a file

When you have a CID of data you want to download, you can use the following commands:

CID="..." # paste your CID from the previous step here between the quotes
curl -o "${CID}.avi" "http://localhost:8080/api/codex/v1/data/${CID}/network"

📢 Note

NOTE: Use the correct extension for the downloaded file.

Note that Codex does not store content-type or extension information.

Local data

You can view which datasets are currently being stored by your node.

curl http://localhost:8080/api/codex/v1/data \
  --write-out '\n'

Create storage availability

📢 Warning 1

Are you currently in a Codex workshop?! Yes: Please skip this step. Proceed with 'Purchase storage'.

📢 Warning 2

This step requires that Codex was started with the 'prover' option.

In order to start selling storage space to the network, you must configure your node with the following command. Once configured, the node will monitor on-chain requests-for-storage and will automatically enter into contracts that meet these specifications. In order to enter and maintain storage contracts, your node is required to submit zero-knowledge storage proofs. The calculation of these proofs will increase the CPU and RAM usage of Codex.

curl --request POST \
  http://localhost:8080/api/codex/v1/sales/availability \
  --header 'Content-Type: application/json' \
  --write-out '\n' \
  --data '{
	"totalSize": "8000000",
	"duration": "7200",
	"minPrice": "10",
	"maxCollateral": "10"
  }'

For descriptions of each parameter, please view the Spec.

Purchase storage

To purchase storage space from the network, first you must upload your data. Once you have the CID, use the following to create a request-for-storage.

Set your CID:

CID="..." # paste your CID from the previous step here between the quotes
echo "CID: ${CID}"

Next you can run:

curl --request POST \
  "http://localhost:8080/api/codex/v1/storage/request/${CID}" \
  --write-out '\n' \
  --data '{
  "duration": "3600",
  "reward": "1",
  "proofProbability": "5",
  "expiry": "1200",
  "nodes": 5,
  "tolerance": 2,
  "collateral": "1"
  }'

For descriptions of each parameter, please view the Spec.

When successful, this request will return a Purchase-ID.

View purchase status

Using a Purchase-ID, you can check the status of your request-for-storage contract:

PURCHASE_ID="..."

Then:

curl "http://localhost:8080/api/codex/v1/storage/purchases/${PURCHASE_ID}" \
  --write-out '\n'

This will display state and error information for your purchase.

State Description
Pending Request is waiting for chain confirmation.
Submitted Request is on-chain. Hosts may now attempt to download the data.
Started Hosts have downloaded the data and provided proof-of-storage.
Failed The request was started, but (too many) hosts failed to provide proof-of-storage on time. While the data may still be available in the network, for the purpose of the purchase it is considered lost.
Finished The request was started successfully and the duration has elapsed.
Expired (Not enough) hosts have submitted proof-of-storage before the request's expiry elapsed.
Errored An unfortunate state of affairs. The 'error' field should tell you more.