API and SDK
API and SDK Documentation
The XSPACE Protocol provides a robust suite of tools, including REST APIs, Web3 integration, and the XSPACE SDK, to empower developers in building decentralized applications and interacting with the blockchain. These resources simplify operations such as querying the blockchain, managing tokens, and interacting with smart contracts.
REST APIs
XSPACE’s REST APIs allow developers to interact with the blockchain without running a full node. They are ideal for querying data, managing accounts, and executing basic blockchain operations.
Base URL
Testnet:
https://api.testnet.xspaceprotocol.io
Mainnet:
https://api.xspaceprotocol.io
API Endpoints
1. Account Management
Get Account Balance
Endpoint:
GET /account/{address}/balance
Description: Retrieve the balance of an account.
Parameters:
address
(string): The wallet address.
Response:
List Transactions
Endpoint:
GET /account/{address}/transactions
Description: Fetch a list of transactions for a specific account.
Parameters:
address
(string): The wallet address.
Response:
2. Smart Contracts
Call Smart Contract Function
Endpoint:
POST /contract/{address}/call
Description: Call a read-only function on a smart contract.
Parameters:
address
(string): The contract address.method
(string): The method signature (e.g.,getBalance()
).params
(array): Parameters for the method.
Response:
Submit Contract Transaction
Endpoint:
POST /contract/{address}/transaction
Description: Submit a transaction to invoke a smart contract method.
Parameters:
address
(string): The contract address.method
(string): The method signature (e.g.,transfer(address,uint256)
).params
(array): Parameters for the method.privateKey
(string): The private key to sign the transaction.
Response:
3. Token Management
Get Token Details
Endpoint:
GET /token/{address}
Description: Fetch details about a specific token.
Parameters:
address
(string): The token contract address.
Response:
Authentication
Some endpoints (e.g., submitting transactions) require authentication using your wallet’s private key. Always ensure keys are stored securely and never exposed publicly.
Web3 Integration
Developers can use Web3.js or Ethers.js to interact with XSPACE smart contracts, tokens, and the blockchain programmatically.
Setting Up Web3.js
Install Web3.js:
Connect to the XSPACE Testnet:
Interact with an Account:
Send a Transaction:
Using Ethers.js
Install Ethers.js:
Connect to the XSPACE Testnet:
Interact with a Smart Contract:
XSPACE SDK
The XSPACE SDK simplifies blockchain development by providing prebuilt methods for common operations like querying data, interacting with smart contracts, and managing accounts.
Installing the SDK
Install the XSPACE SDK via npm:
Using the SDK
Initialize the SDK
Query Account Balance
Deploy a Smart Contract
Interact with a Contract
Developer Resources
This suite of APIs and tools provides developers with everything needed to efficiently build and deploy applications on the XSPACE Protocol.
Last updated