Developers

Technical resources for developers building on Libre Chain and integrating with the lending platform.

Overview

Libre Chain provides a robust platform for building decentralized applications, with particular focus on Bitcoin-native financial services. This section covers smart contract development, API integration, and technical resources.

Quick Start

Network Information

  • Chain ID: 1

  • RPC Endpoint: https://libre-api.libre.org

  • Explorer: https://libre.antelope.tools

  • Testnet RPC: https://libre-testnet-api.libre.org

Core Contracts

  • Lending Pools: lending.libre

  • DEX: swap.libre

  • Bridge: bridge.libre

  • Governance: dao.libre

Smart Contract Development

Development Environment

Libre Chain uses the Antelope (formerly EOSIO) smart contract platform:

  • Language: C++

  • Framework: Antelope CDT

  • Testing: Local testnet with cleos

  • Deployment: Multi-sig governance process

Getting Started

# Install Antelope CDT
wget https://github.com/AntelopeIO/cdt/releases/download/v3.0.1/cdt_3.0.1_amd64.deb
sudo apt install ./cdt_3.0.1_amd64.deb

# Clone template contract
git clone https://github.com/libre-chain/libre-contract-template
cd libre-contract-template

# Build contract
mkdir build && cd build
cmake .. && make

Example: Simple Lending Integration

#include <eosio/eosio.hpp>
#include <eosio/asset.hpp>

class [[eosio::contract]] mylender : public eosio::contract {
public:
    using contract::contract;

    // Deposit USDT to lending pool
    [[eosio::action]]
    void deposit(name user, asset quantity, uint32_t pool_id) {
        require_auth(user);
        
        // Transfer USDT to lending contract
        action(
            permission_level{get_self(), "active"_n},
            "tether.libre"_n,
            "transfer"_n,
            std::make_tuple(get_self(), "lending.libre"_n, quantity, std::string("deposit"))
        ).send();
        
        // Call lending contract deposit action
        action(
            permission_level{get_self(), "active"_n},
            "lending.libre"_n,
            "deposit"_n,
            std::make_tuple(user, quantity, pool_id)
        ).send();
    }
};

API Integration

REST API Endpoints

Pool Information

# Get all lending pools
curl https://libre-api.libre.org/v1/chain/get_table_rows \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "code": "lending.libre",
    "table": "pools",
    "scope": "lending.libre",
    "json": true
  }'

User Positions

# Get user lending positions
curl https://libre-api.libre.org/v1/chain/get_table_rows \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "code": "lending.libre",
    "table": "positions",
    "scope": "USERNAME",
    "json": true
  }'

WebSocket Streaming

// Real-time pool updates
const ws = new WebSocket('wss://libre-api.libre.org/v1/stream');

ws.on('message', (data) => {
    const update = JSON.parse(data);
    if (update.table === 'pools') {
        console.log('Pool update:', update.data);
    }
});

// Subscribe to pool updates
ws.send(JSON.stringify({
    action: 'subscribe',
    table: 'lending.libre/pools'
}));

SDK Integration

JavaScript SDK

npm install @libre-chain/lending-sdk
import { LibreLending } from '@libre-chain/lending-sdk';

const lending = new LibreLending({
    rpcEndpoint: 'https://libre-api.libre.org',
    network: 'mainnet'
});

// Get pool information
const pools = await lending.getPools();

// Deposit to pool
const result = await lending.deposit({
    user: 'myaccount',
    amount: '1000.0000 USDT',
    poolId: 1,
    privateKey: 'YOUR_PRIVATE_KEY'
});

Python SDK

pip install libre-lending-sdk
from libre_lending import LibreLending

lending = LibreLending(
    rpc_endpoint='https://libre-api.libre.org',
    network='mainnet'
)

# Get pool data
pools = lending.get_pools()

# Calculate potential returns
returns = lending.calculate_returns(
    principal=10000,
    pool_id=1,
    duration_days=90
)

Bridge Integration

Bitcoin Deposits

// Monitor Bitcoin deposits
import { LibreBridge } from '@libre-chain/bridge-sdk';

const bridge = new LibreBridge({
    network: 'mainnet',
    bitcoinNetwork: 'mainnet'
});

// Generate deposit address for user
const depositAddress = await bridge.generateDepositAddress('username');

// Monitor for confirmations
bridge.onDeposit(depositAddress, (tx) => {
    console.log('Bitcoin deposited:', tx);
    // Handle bridge completion
});

USDT Bridge

// Bridge USDT from Ethereum
const bridgeTx = await bridge.bridgeUSDT({
    fromNetwork: 'ethereum',
    toNetwork: 'libre',
    amount: '1000.000000', // 6 decimals for USDT
    recipient: 'libre-account'
});

Testing & Development

Local Testnet Setup

# Start local Libre node
git clone https://github.com/libre-chain/libre-testnet
cd libre-testnet
docker-compose up -d

# Create test accounts
cleos create account eosio alice ALICE_PUBLIC_KEY
cleos create account eosio bob BOB_PUBLIC_KEY

# Deploy contracts
cleos set contract lending ./contracts/lending

Test Data

# Create test USDT
cleos push action tether.libre create '["tether.libre", "1000000.000000 USDT"]' -p tether.libre

# Issue test tokens
cleos push action tether.libre issue '["alice", "10000.000000 USDT", "test funds"]' -p tether.libre

# Create test pool
cleos push action lending.libre createpool '[1, "30 days", 900, "alice"]' -p alice

Security Considerations

Smart Contract Security

  • Reentrancy protection: Use proper state management

  • Authorization checks: Validate all user permissions

  • Overflow protection: Use safe math libraries

  • Input validation: Sanitize all external inputs

API Security

  • Rate limiting: Implement request throttling

  • Authentication: Use signed transactions for state changes

  • Input validation: Validate all API parameters

  • HTTPS only: Always use encrypted connections

Resources

Documentation

Tools

Support

Legacy Developer Resources

For comprehensive technical documentation, see:

Contributing

Libre Chain is open source. Contributions welcome:

  1. Fork the repository

  2. Create feature branch

  3. Submit pull request

  4. Follow coding standards

  5. Include tests for new features

The platform is designed to be developer-friendly while maintaining the security and transparency that Bitcoin users expect.

Last updated

Was this helpful?