JavaScript SDK for integrating with the Cipherblock blockchain - a portable cryptographic reputation management system.
- Wallet Management: Create, import, export, and manage multiple wallets
- Transaction Building: Build and sign all transaction types (transfers, NFTs, ratings, burns)
- Blockchain Interaction: Submit transactions, request tokens, query state
- Multi-Wallet Support: Manage multiple accounts with easy switching
- Cryptographic Operations: Sign/verify messages, hash data, generate keypairs
- Firebase Integration: Direct access to blockchain state via Firestore (optional)
npm install cipherblock-sdkIf you want to access blockchain state directly (balances, transactions, NFTs), also install Firebase:
npm install firebaseimport { createCipherblockSDK } from 'cipherblock-sdk';
// Create SDK instance
const sdk = createCipherblockSDK();
// Initialize (loads wallets from localStorage)
await sdk.init();
// Get or create wallet
const wallet = sdk.getWallet();
console.log('My Address:', wallet.address);
// Request tokens from faucet (once per address)
const faucetResult = await sdk.requestTokens();
console.log('Received:', faucetResult.amount, 'tokens');import { initializeApp } from 'firebase/app';
import { createCipherblockSDK } from 'cipherblock-sdk';
// Initialize Firebase
const firebaseApp = initializeApp({
apiKey: "AIzaSyBuE6iu4v3hf01exw_RRqYAr_YM4IZTWu8",
authDomain: "cipherblockio.firebaseapp.com",
projectId: "cipherblockio",
storageBucket: "cipherblockio.appspot.com"
});
// Create SDK with Firebase
const sdk = createCipherblockSDK({ firebaseApp });
await sdk.init();
// Check balance
const balance = await sdk.getBalance();
console.log('Balance:', balance, 'CBT');
// Send tokens
const result = await sdk.sendTokens(recipientAddress, 5.0);
console.log('Transaction Hash:', result.tx_hash);
// Get transaction history
const history = await sdk.client.getTransactionHistory(wallet.address);
console.log('Transactions:', history);Creates a new SDK instance.
Options:
firebaseApp: Firebase app instance (optional, required for state access)submitTransactionUrl: Custom transaction endpoint (optional)requestTokensUrl: Custom faucet endpoint (optional)
Returns: SDK instance with:
client: BlockchainClient instancewalletManager: WalletManager instanceinit(): Initialize SDK (load wallets)getWallet(): Get or create active walletsendTokens(recipient, amount): Send tokensrequestTokens(): Request from faucetgetBalance(): Get balance of active wallet
Create a new wallet. If no keypair is provided, generates a new one.
Methods:
export(): Export wallet data as objectexportJSON(): Export wallet data as JSON stringgetPublicInfo(): Get address and public key only
Static Methods:
Wallet.import(data): Import wallet from objectWallet.importJSON(jsonString): Import wallet from JSON
Manages multiple wallets with localStorage persistence.
Methods:
createWallet(): Create and add new walletaddWallet(wallet): Add existing walletgetActiveWallet(): Get currently active walletsetActiveWallet(index): Switch active walletgetAllWallets(): Get all walletsgetWalletByAddress(address): Find wallet by addresssave(): Save to localStorageload(): Load from localStorageclear(): Remove all wallets
Client for blockchain interactions.
Methods:
State Queries:
getState(): Get current blockchain stategetBalance(address): Get token balancegetNonce(address): Get transaction noncegetNFTsOwnedBy(address): Get owned NFTsgetBlocks(start, end): Get blocks in rangegetLatestBlocks(count): Get recent blocksgetTransactionHistory(address, maxBlocks): Get transaction history
Transactions:
submitTransaction(transaction, privateKey): Submit signed transactionrequestTokens(address): Request tokens from faucet
Transaction Builders:
buildTokenTransfer(sender, recipient, amount, nonce)buildRateTransaction(sender, target, score, nonce)buildNFTMint(sender, nftHash, nonce)buildNFTTransfer(sender, recipient, nftHash, nonce)buildNFTSellOrder(sender, nftHash, price, expiration, nonce)buildNFTBuyOrder(sender, nftHash, price, expiration, nonce)buildTokenBurn(sender, amount, destinationKey, nonce)buildNFTBurn(sender, nftHash, destinationKey, nonce)
Generate a new secp256k1 keypair.
Returns: { privateKey, publicKey, address }
Sign a transaction.
Returns: Promise resolving to signature hex string
Verify a transaction's signature.
Returns: Boolean
Sign an arbitrary message (off-chain).
Returns: Promise resolving to signature hex string
Verify a message signature.
Returns: Boolean
Hash data with SHA256.
Returns: Hex string
Check if address format is valid.
Returns: Boolean
Check if private key format is valid.
Returns: Boolean
Transfer tokens to another address.
const nonce = await client.getNonce(wallet.address);
const tx = client.buildTokenTransfer(
wallet.address,
recipientAddress,
5.0, // amount
nonce
);
await client.submitTransaction(tx, wallet.privateKey);Fee: 0.001 CBT
Rate another address (reputation).
const tx = client.buildRateTransaction(
wallet.address,
targetAddress,
75, // score: -100 to 100
nonce
);Fee: 0.001 CBT
Create a new NFT.
import { hashData } from 'cipherblock-sdk';
const nftHash = hashData(JSON.stringify({ name: 'My NFT', image: '...' }));
const tx = client.buildNFTMint(wallet.address, nftHash, nonce);Fee: 0.001 CBT
Transfer an owned NFT.
const tx = client.buildNFTTransfer(
wallet.address,
recipientAddress,
nftHash,
nonce
);Fee: 0.001 CBT
List an NFT for sale.
const expiration = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString();
const tx = client.buildNFTSellOrder(
wallet.address,
nftHash,
10.0, // price
expiration,
nonce
);Fee: 0.001 CBT (NFT gets locked until order completes or expires)
Make an offer to buy an NFT.
const expiration = new Date(Date.now() + 7 * 24 * 60 * 60 * 1000).toISOString();
const tx = client.buildNFTBuyOrder(
wallet.address,
nftHash,
10.0, // price
expiration,
nonce
);Fee: 0.001 CBT (tokens get locked until order completes or expires)
Burn tokens or NFTs.
// Burn tokens
const tx = client.buildTokenBurn(
wallet.address,
5.0, // amount
'bitcoin:1A1zP1eP...', // destination key
nonce
);
// Burn NFT
const tx = client.buildNFTBurn(
wallet.address,
nftHash,
'ethereum:0x123...', // destination key
nonce
);Fee: 0.001 CBT
Standard transaction fee: 0.001 CBT
All transactions require this fee to be deducted from the sender's balance.
See the examples/ directory for complete working examples:
- basic-usage.js: Simple wallet and faucet usage
- advanced-usage.js: Full features with Firebase integration
- wallet-management.js: Multi-wallet operations and import/export
The SDK works in both Node.js and browsers. For browsers, use a bundler like webpack or vite:
<script type="module">
import { createCipherblockSDK } from './dist/cipherblock-sdk.js';
const sdk = createCipherblockSDK();
// ... use SDK
</script>Wallets are automatically saved to localStorage in browsers.
- Private Keys: Never expose private keys in client-side code or commit them to version control
- Key Storage: In production, use secure key storage solutions (hardware wallets, encrypted storage)
- HTTPS Only: Always use HTTPS in production to protect API calls
- Validate Input: Always validate user input before building transactions
- Rate Limiting: Be aware of faucet limits (5 tokens per address, 250/day globally)
MIT
For issues and questions:
- GitHub Issues: https://github.com/cipherblock/cipherblock-sdk/issues
- Cipherblock Docs: https://cipherblock.io/docs
Contributions are welcome! Please open an issue or pull request.