To make the Numbers Protocol developer ecosystem more accessible, we've leveraged familiar concepts to create Capture SDK and Capture Token for API access. The Capture Token allows developers to perform tasks like updating asset history, tracing asset provenance, and generating AI images with blockchain validation. For experienced Web3 developers, our open-source tools like 'nit' continue to offer direct development via wallets or private keys.
In this tutorial we will help you begin your development journey by covering both tradition and Web3 methods of how to acquire a Capture Token. Let us begin!
Registering a Capture Account
Before we can acquire the Capture Token, we will need to create an account. This can be done easily through Capture Cam or through Capture Dashboard.
If you wish to create an account via API, you will need to acquire an API key by contacting service@numbersprotocol.io.
Now that we have our account all set up, let’s get our Capture Token!
Getting Capture Token
Verifying Capture Token
Let us put our Capture Token’s to use and verify the tokens' validity by running a GET request to https://api.numbersprotocol.io/api/v3/auth/users/me with our Capture Token passed in as Authorization Header.
A successful response will output all the relevant account information:
{
"id": 38,
"address": "<wallet address>",
"username": "<account username>",
"email": "<account email>",
"groups": [
"email_verified",
"phone_verified"
],
"email_verified": true,
"phone_verified": true,
"language": "en-us",
"asset_count": 367,
"asset_total_bytes": 2180159355,
...
Acquiring Capture Token via Wallet Login
An alternative approach to acquiring your Capture Token is through wallet login. While not as straightforward as previously outlined methods, this approach offers developers a more Web3 method of acquiring the Capture Token.
Wallet Login is done with your accounts Signature Wallet which in the Numbers Protocol network is used for creating signatures. By combining your Signature Wallet with client side code communicating with a wallet such as MetaMask and a few Capture API calls we can execute the wallet login.
Below is a code snippet for wallet login:
const url = `https://api.numbersprotocol.io/api/v3/auth/token/login-web3/`;
// Request the user's address from their wallet using the 'eth_requestAccounts' method
const address = (await ethereum.request({ method: 'eth_requestAccounts' }))[0];
// Send a GET request to the server to receive the message to be signed
let getResponse = await fetch(`${url}?address=${address}`));
// Get the message to be signed from the response
let message = (await getResponse.json()).message;
// Sign the message with the user's wallet
let signature = await ethereum.request({method: 'personal_sign', params: [address, message]});
// Send a POST request to the server with the address and signature to retrieve the auth token
let postResponse = await fetch(`${endpoint}`, {
method: 'POST',
body: JSON.stringify({address, signature}),
headers: {'Content-type': 'application/json'}
});
// Get the auth token from the response
let authToken = (await postResponse.json()).auth_token;
Next Steps
In this walkthrough, we covered how to create a Capture Account and most importantly how to acquire the Capture Token. We also demoed how to pass in the Capture Token as an Authorization Header to verify your Capture Account. For a developer, the Capture Token is a key starting point for your Numbers Protocol development journey. With it you can perform asset registration as well as create commits on Numbers Blockchain. We will have walkthroughs for each of these coming in the future so stay tuned.
If you had trouble acquiring your Capture Token feel free to drop a question in our community channels.
We will do our best to resolve your issues as soon as possible!