Blockchain-as-a-Service (BaaS) platforms empower developers to build, deploy, and manage blockchain applications efficiently. A critical component of any BaaS solution is its JavaScript Software Development Kit (JS SDK), which provides a suite of APIs for interacting with the blockchain network programmatically. This guide delivers a comprehensive overview of the supported JS APIs within a typical contract-based blockchain platform, detailing their functions, use cases, and return value structures.
Whether you're building decentralized applications (dApps), automating smart contract interactions, or integrating blockchain functionality into existing systems, understanding these APIs is essential. Below, we break down each API category with clear explanations and practical context.
Environment Interface
The foundation of any blockchain interaction begins with initializing the environment. This step establishes a secure connection to the blockchain network.
Chain
: Initializes the environment instance. Before performing any operation—be it account creation or contract deployment—you must instantiate the chain using configuration parameters such as node URL, chain ID, and authentication credentials.
👉 Discover how to set up your blockchain environment in minutes
Account Interface
User identities on the blockchain are represented through accounts. These interfaces allow for full lifecycle management of blockchain accounts.
CreateAccount
: Generates a new blockchain account with a unique public-private key pair.TransferBalance
: Executes value transfers between accounts, similar to sending cryptocurrency in traditional networks.SetRecoverKey
: Assigns a recovery public key, enabling account recovery under predefined conditions.PreResetPubKey
andResetPubKey
: Together, these enable secure public key rotation—a crucial feature for long-term account security.UpdateAuthMap
: Modifies the authorization weights associated with an account, useful in multi-signature or role-based access control scenarios.
These tools ensure robust identity and access management within the decentralized ecosystem.
Contract Interface
Smart contracts are self-executing programs that power most advanced blockchain applications. This interface set allows full interaction with them.
contract
: Constructs an instance of a deployed smart contract, preparing it for method calls.new
: Deploys a new smart contract to the blockchain using compiled bytecode.[Custom Contract Method Name]
: Invokes any public function defined within a smart contract—such as updating data or triggering payments.update
: Upgrades an existing contract, allowing for bug fixes or feature enhancements without losing state.
Developers can use these methods to automate business logic execution on-chain securely.
👉 Learn how to deploy your first smart contract today
Query Interface
Transparency and auditability are core principles of blockchain technology. The query interface enables retrieval of on-chain data.
QueryBlockHeader
,QueryLastBlock
,QueryBlock
: Retrieve metadata about specific blocks, including timestamps, hashes, and validator information.QueryTransaction
andQueryTransactionReceipt
: Fetch details about a transaction and its execution result (e.g., gas used, status).QueryAccount
andQueryContract
: Inspect current states of accounts and smart contracts, such as balance or storage values.
These queries are read-only operations and do not incur transaction fees, making them ideal for monitoring and analytics.
Local Execution Interface
For testing or simulation purposes, certain operations can be executed locally without broadcasting to the network.
LocalTransaction
: Simulates a standard transaction execution off-chain to preview outcomes.[Contract-Related Operation Methods]
: Allows local invocation of contract functions to test logic before actual deployment.
This capability significantly reduces development risk and accelerates debugging.
Native Evidence Interface
One of the most powerful use cases of blockchain is immutable data anchoring—proving that data existed at a certain point in time.
NativeDepositData
: Stores cryptographic proof of data directly onto the blockchain. Unlike storing full files, this method records only a hash, ensuring privacy while maintaining verifiability.
Use cases include document certification, intellectual property protection, and audit trail generation.
Event Interface
Real-time responsiveness is vital in dynamic applications. The event system supports asynchronous notifications based on on-chain activities.
event.account
,event.contract
,event.topic
,event.block
: Subscribe to changes related to accounts, contracts, custom topics, or new blocks..close
variants: Terminate subscriptions gracefully when no longer needed.[Subscribe to Custom Contract Events]
: Listen for user-defined events emitted by smart contracts (e.g., "PaymentReceived", "OwnershipTransferred").
This enables reactive architectures where backend systems respond instantly to blockchain events.
Auxiliary Utility Interface
These helper functions simplify common development tasks and improve code readability.
getHash
: Computes a cryptographic hash (e.g., SHA-3) of input data—essential for generating unique identifiers or proofs.toDecimal
: Converts hexadecimal numbers into human-readable decimal format.toUtf8
: Decodes hex-encoded strings back into readable text.getKeyInfo
: Retrieves metadata about an account’s keys and permissions.
These utilities reduce boilerplate code and enhance interoperability across components.
Return Value Structure
Understanding API responses is crucial for error handling and data processing.
Standard Interface Response
Most non-contract APIs follow this pattern:
err
: A string describing any error;undefined
indicates success.data
: An object containing the result payload—for example, transaction receipts or queried account details.
Contract Deployment & Invocation Response
Slightly different due to the nature of smart contract execution:
err
: Error message if present.output
: Varies by context:- For deployment, returns the contract’s bytecode.
- For invocation, reflects the actual return value defined in the contract method (e.g., boolean, string, struct).
data
: Always includes the transaction receipt, which confirms inclusion in a block and execution status.
Always validate botherr
anddata.status
fields to ensure successful execution.
Frequently Asked Questions
Q: Can I use these APIs with mobile apps?
A: Yes. The JS SDK can be integrated into hybrid mobile applications using frameworks like React Native or Ionic.
Q: Are there rate limits on API usage?
A: Rate limits depend on your service plan and node access type. Private nodes typically offer higher throughput than shared gateways.
Q: How do I handle failed transactions?
A: Check the err
field first. If absent but data.status
is false, the transaction failed during execution—review gas settings or contract logic.
Q: Is local execution safe for testing sensitive logic?
A: Yes. Local execution does not interact with the live chain, making it safe for testing. However, behavior may slightly differ from on-chain execution due to environment variances.
Q: What security practices should I follow when managing keys?
A: Never hardcode private keys. Use secure key management solutions like hardware security modules (HSMs) or encrypted vaults.
Q: Can I monitor multiple contracts simultaneously?
A: Absolutely. Use event.contract
with filters or subscribe to custom events across multiple contract addresses.
Core Keywords: blockchain API, smart contract deployment, JS SDK, BaaS platform, on-chain data query, event subscription, local transaction execution, cryptographic evidence