Get your Capture Token

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 [email protected].

Download Capture for iOS or Android, click “Create an Account” and fill in fields to create an account

Navigate to Capture Dashboard click on “Create an account’ and fill in information to create an account

Now that we have our account all set up, let’s get our Capture Token!

Getting Capture Token

Utilize POST https://api.numbersprotocol.io/api/v3/auth/token/login/ with email & password payload to login and acquire auth_token.

curl --location 'https://api.numbersprotocol.io/api/v3/auth/token/login/' \
--header 'Content-Type: application/json' \
--data-raw '{
    "email": "<capture-email>",
    "password": "<capture-password>"
}'

Successful login event will output an auth_token response. This auth_token can be passed in as Authorization Header for future Capture API functions.

// Stauts: 200 OK
{
    "auth_token": "<capture-token>"
}

Verifying Capture Token

By making a request to the endpoint below with a valid token included in the headers, the user is able to verify their token and access the resources or services that are protected by the token. This endpoint is useful for ensuring that a user is authorized to access certain content or perform certain actions on a website or application. Additionally, this endpoint could also be used to check the validity of a token during a user's session.

The following sample codes can be used to validate the Capture Token.

curl -X GET https://api.numbersprotocol.io/api/v3/auth/users/me?show_num_balance=true \
     -H "Authorization: token $USER_CAPTURE_TOKEN"

The response.data.results[0] is the JSON object containing the user information. Following is an example of a JSON object returned by an API endpoint. The object contains information about a user, including their address, username, email, language, and wallet information.

// Status: 200 OK
{
  "address": "0x8212099e5aF75e555A3E63da77a99CcC9527aCC1", # integrity wallet address
  "username": "Foo Bar",
  "email": "[email protected]",
  "asset_count": 628,
  "asset_total_bytes": 2583898055,
  "user_wallet": {
    "asset_wallet": "0x29e467Cc273AA94CAD88dB4acead4F38b2075521", # wallet address
    "asset_wallet_num": "3.089975119133574007", # NUM balance
    "integrity_wallet": "0x8212099e5aF75e555A3E63da77a99CcC9527aCC1", # wallet address
    "integrity_wallet_num": "1", # NUM balance
    "points": "159.8", # Capture Credits balance
  },
  "referrer": null, # who referred the user
  "referral_code": "SV9GKA", # user's referral code
  "referee_count": "5", # number of users that joined using the user's referral code
  "joined_at": "2020-11-14T12:24:24.822000Z" # datetime when the user created an account
  ...
}

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 Integrity Wallet which in the Numbers Protocol network is used for creating signatures. By combining your Integrity 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!

Last updated