Over the past few years, there has been growing interest in finding more decentralized methods of storing data due to the growing concerns surrounding data accessibility and increasing distrust in centralized entities controlling our data. The decentralized web is a reorganization of the internet where peer-to-peer infrastructure is used as opposed to the more traditional centralized data hosting services. One of these key decentralized infrastructures is IPFS (Interplanetary File System).
In this tutorial, we will cover how you can use Numbers Protocol Asset Registration API to pin files on IPFS as well as store files on Filecoin.
Setting the Stage: What You Need to Begin
The Numbers Protocol API requires users to have access to what we call the Capture Authorization Token. To learn more about how to acquire the Capture Authorization Token, you can refer to the official documentation or follow along in [Start Developing with Numbers Protocol: Get your Capture Token]
Visualizing the Process: A Peek into the Data Journey
Pinning files on IPFS with Numbers Protocol “Register Asset” API is just one step in the entire process. When files are registered in this manner, they become Web3.0 assets. This means they are decentralized, hence the IPFS pinning and Filecoin storage, and become traceable and verifiable with on-chain records.
Since the focus of this article is on IPFS pinning, that will be the focus of this article. If you are interested in the details of on-chain records, please check out [Unlocking the Future: A Dive into the AI-Blockchain Synergy with Numbers Protocol and Instill AI] to learn more.
Guided Steps for IPFS Pinning Success
To pin files onto IPFS, we will use the Numbers Protocol “Register Asset” API endpoint. By sending a POST request to https://api.numbersprotocol.io/api/v3/assets/, we not only are pinning our file to Numbers IPFS Gateway, but we are also creating an on-chain provenance record for our asset. Full API endpoint details are below:
Authorization (string): token <Capture Authorization Token>
Content-Type (string): multipart/form-data
Let’s call this API by setting up a POST request in Postman. Under the Header section, we add the fields Authorization and Content-Type and fill in with our Capture Authorization Token and multipart/form-data. See below:
For our request body, let’s set it to form-data and add in the asset_file field, making sure to set it to File type. Since asset_file is the only required field, all we need to do is upload our file and click SEND.
DONE! We have successfully pinned our file onto IPFS. Our Response Body returns us many fields, however we are most interested in the id field, which indicates the assets content id. This content id is what we will be using to open the file on IPFS. For this example it is bafybeieywiocozfpbk5neh66aelkwgqp3zmma7demej7inkgh5fcfyzk4a.
We can pull up this file by navigating to Numbers IPFS gateway : https://ipfs-pin.numbersprotocol.io/ipfs/<asset id>
For our example, this is the final pinned file: https://ipfs-pin.numbersprotocol.io/ipfs/bafybeieywiocozfpbk5neh66aelkwgqp3zmma7demej7inkgh5fcfyzk4a
If you prefer not to use Postman, you can also run using cURL with the following:
curl — location — request POST ‘https://api.numbersprotocol.io/api/v3/assets/' \
— header ‘Authorization: token <Capture Authorization Token> \
— header ‘Content-Type: multipart/form-data’ \
— form ‘asset_file=@”/Users/ethanwu/Desktop/366074295_10159706671016662_8487550833018552612_n.jpeg”’
Reflections and What Lies Ahead in the Decentralized Realm
In this tutorial, we covered how to use the Numbers “Register Asset” API to pin files onto the decentralized web, specifically IPFS. Doing so alters the data landscape as files will always be accessible and no longer to censorship or uncontrolled server failures.
Registering assets via Numbers Protocol API is simple and can be expanded on to make assets more decentralized and made more trustworthy with fuller provenance. If you are interested in how that is done, you can reference the official documentation or wait for more written tutorials on the topic to learn more.
It’s also important to note that Numbers API operates on a pay-as-you-go system, meaning you pay only as much as you use it. Payments are done with our native NUM token or through NUM Credits, and accounts can be topped up when necessary. As an added benefit for first-time users, we will provide 12 credits, which equates to roughly 120 registrations. To learn more about these payment methods, please visit here for information.
Happy Pinning! Also, if you have any questions, feel free to tune into our community channels and ask you questions.