Quickstart
Let's start using Blockmate APIs to create your basic app.
We'll go through these few simple steps:
Create end-user
↓
Authenticate end-user
↓
Connect Onchain wallets / CEXs / NFTs
↓
Integrate Account information endpoints into your app
Registration
- ⚡️ Register for the Blockmate's portal ⚡️
- Create new project - virtual entity as a group of end-users
- Generate new key token
To interact with all API services you need to have a project authorization token
.
If you already have your token, you're ready to start coding. If not, please Register HERE
Now, when you have a token, you can jump in and check out how it all works, add your API token and run this example python script:
- Install python3 - 'Windows/Linux/Mac tutorials'
- Install the required library
pip3 install requests
- Paste your token into the
my_project_token
variable - Execute the following python script:
python3 ./blockmate-demo.py
#!/usr/bin/python3
import requests
import json
import time
import sys
# Fill in your token
my_project_token="paste_your_token_here"
# Create a user
r = requests.post("https://api.blockmate.io/v1/users", json={"name": "test-user"}, headers={"X-API-KEY": my_project_token})
user_uuid = r.json()["uuid"]
print(f"We got user with id: {user_uuid}")
# Authenticate the user
r = requests.get(f"https://api.blockmate.io/v1/users/{user_uuid}/auth", headers={"X-API-KEY": my_project_token})
user_jwt_token = r.json()["token"]
print(f"We got JWT token for the user")
# Connect a BTC wallet (account) to user
r = requests.post("https://api.blockmate.io/v1/onchain/btc/connect", json={"description": "My test btc address", "wallet": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh"}, headers={"Authorization": f"Bearer {user_jwt_token}"})
account_id = r.json()["id"]
print(f"We connected an account to user with id: {account_id}")
# Get the balance, when it's ready
print("Waiting for sync", end="")
while True:
r = requests.get(f"https://api.blockmate.io/v1/onchain/btc/account/{account_id}/balance", headers={"Authorization": f"Bearer {user_jwt_token}"})
balance = r.json()
sys.stdout.write(".")
sys.stdout.flush()
if balance["state"]["last_sync"] is not None: break
time.sleep(1)
print()
print("=== Balance ===")
print(balance["balance"])
# Get the transactions
r = requests.get(f"https://api.blockmate.io/v1/onchain/btc/account/{account_id}/transactions", headers={"Authorization": f"Bearer {user_jwt_token}"})
transactions = r.json()
print("=== Transactions ===")
print(json.dumps(transactions["transactions"], indent=4))
If you would like to go step by step please follow the instructions:
1/ Register End-users
For working with Project level API endpoints you need to add a project authorization token in each request in the header:
Request
Header
Security Scheme Type: API Key
Header parameter name: X-API-KEY
POST <https://api.blockmate.io/v1/users
>
{
"name": "some-name"
}
Response
{
"uuid": "4301140e-d639-11ec-9120-00155d03ab64",
"name": "some-name"
}
2/ Authenticate End-user
From the response from step #1 you will get the End-user ID (uuid).
Using uuid as url parameter and the same header as in the previous step, you will authenticate end-user for subsequent operations.
Request
GET <https://api.blockmate.io/v1/users/{uuid}/auth
>
Response
{
"token": "string"
}
From this point, you will be using JTW token from this response as Authorization header parameter.
3/ Connect your Bitcoin wallet
Request
Header
Authorization: "Bearer {token}"
POST /v1/onchain/{onchain}/connect
for example, adding Bitcoin wallet to your account
POST /v1/onchain/btc/connect
{
"wallet": "bc1qxy2kgdygjrsqtzq2n0yrf2493p83kkfjhx0wlh",
"description": "string"
}
Response
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"description": "string"
}
4/ Basic operations
Request balance information for single account connection:
account_id
is a variable from the previous call
GET <https://api.blockmate.io/v1/onchain/{onchain}/account/{account_id}/balance
>
Response
{
"property1": 0,
"property2": 0
}
5/ Advanced operations
To get the cumulative balance from every connected asset, you need to call just one endpoint.
Request
GET <https://api.blockmate.io/v1/aggregate/balance
>
Response
{
"BTC": 10.1,
"LTC": 2.2,
...
}
Updated over 1 year ago