Skip to main content

Bitmark API

Multiple APIs are available for integrating with Bitmark.

API Options​

APITypeUse Case
RPC APIJSON-RPCNode operations, wallet
REST APIHTTP RESTWeb apps, explorers
ElectrumXStratumLight wallets

bitmark-api (REST)​

A modern REST API with blockchain indexer.

Repository​

github.com/project-bitmark/bitmark-api

Quick Start​

# Clone
git clone https://github.com/project-bitmark/bitmark-api.git
cd bitmark-api

# Install
npm install

# Configure
cp .env.example .env
# Edit .env:
# RPC_USER=bitmarkrpc
# RPC_PASSWORD=yourpassword
# RPC_HOST=127.0.0.1
# RPC_PORT=9266

# Start
npm start

Endpoints​

Status​

# Sync status
GET /api/status

Response:

{
"height": 500000,
"syncedTo": 500000,
"syncing": false,
"bestBlockHash": "0x1a2b3c..."
}

Blocks​

# Get block by height
GET /api/block/:height

# Get block by hash
GET /api/block/:hash

Transactions​

# Get transaction
GET /api/tx/:txid

# Broadcast transaction
POST /api/tx/broadcast
Content-Type: application/json
{"hex": "<raw_transaction>"}

Addresses​

# Get address info
GET /api/address/:address

# Get UTXOs
GET /api/address/:address/utxos

# Get balance
GET /api/address/:address/balance

# Get transaction history
GET /api/address/:address/txs

Marks​

# Get marks by hash
GET /api/marks?hash=<reference_hash>

# Get marks by type
GET /api/marks?type=1

# Create mark
POST /api/mark
Content-Type: application/json
{
"type": 1,
"reference": "https://example.com/article"
}

References​

# Store reference
POST /api/reference
Content-Type: application/json
{
"reference": "https://example.com/article",
"hash": "8823a419..."
}

# Get reference
GET /api/reference/:hash

RPC API​

Direct JSON-RPC interface to bitmarkd.

Configuration​

In bitmark.conf:

server=1
rpcuser=bitmarkrpc
rpcpassword=yourpassword
rpcallowip=127.0.0.1
rpcport=9266

Making Requests​

# Using curl
curl -u bitmarkrpc:yourpassword \
-d '{"jsonrpc":"1.0","method":"getinfo","params":[]}' \
http://127.0.0.1:9266/

# Using bitmark-cli
bitmark-cli getinfo

Common RPC Methods​

Blockchain​

MethodDescription
getblockchaininfoChain status
getblockBlock details
getblockhashHash by height
getblockcountCurrent height

Wallet​

MethodDescription
getbalanceWallet balance
getnewaddressGenerate address
sendtoaddressSend coins
listtransactionsTransaction list

Network​

MethodDescription
getnetworkinfoNetwork status
getpeerinfoConnected peers
getconnectioncountPeer count

Mining​

MethodDescription
getmininginfoMining status
setgenerateStart/stop mining
setminingalgoSet algorithm

Example Responses​

# getblockchaininfo
{
"chain": "main",
"blocks": 500000,
"headers": 500000,
"bestblockhash": "0x1a2b3c...",
"difficulty": 12345.678,
"mediantime": 1705312000,
"verificationprogress": 1.0
}

ElectrumX Protocol​

For light wallet integrations.

Server​

github.com/project-bitmark/electrumx-bitmark

Connection​

import electrumx_client

client = electrumx_client.Client("electrumx.bitmark.co:50002")

# Get address balance
balance = client.blockchain_scripthash_get_balance(scripthash)

# Get transaction history
history = client.blockchain_scripthash_get_history(scripthash)

Methods​

MethodDescription
blockchain.scripthash.get_balanceAddress balance
blockchain.scripthash.get_historyTransaction history
blockchain.scripthash.listunspentUTXOs
blockchain.transaction.getRaw transaction
blockchain.transaction.broadcastBroadcast tx

Code Examples​

Node.js​

const axios = require('axios');

const api = axios.create({
baseURL: 'http://localhost:3000/api'
});

// Get balance
async function getBalance(address) {
const res = await api.get(`/address/${address}/balance`);
return res.data.balance;
}

// Send transaction
async function broadcast(hex) {
const res = await api.post('/tx/broadcast', { hex });
return res.data.txid;
}

Python​

import requests

API_URL = "http://localhost:3000/api"

def get_balance(address):
r = requests.get(f"{API_URL}/address/{address}/balance")
return r.json()["balance"]

def broadcast_tx(hex_tx):
r = requests.post(f"{API_URL}/tx/broadcast", json={"hex": hex_tx})
return r.json()["txid"]

JavaScript (Browser)​

async function getMarks(hash) {
const response = await fetch(
`https://api.bitmark.co/api/marks?hash=${hash}`
);
return await response.json();
}

Rate Limits​

Public APIs may have rate limits:

EndpointLimit
Status100/min
Block60/min
Address30/min
Broadcast10/min

For higher limits, run your own API instance.

See Also​