Hibit: Omni-chain DEX with CEX-level performance
  • Overview
    • Why Hibit DEX
    • Hibit L1 Features
  • Core mechanisms
    • ๐Ÿ“œHybrid Consensus Protocol
    • ๐Ÿ”AI-Driven Tokenization & Intelligent Interactions
    • โ›ฝOmni-Chain Compatibility
    • ๐Ÿง AI-Powered Liquidity & Order Matching Engine
    • ๐ŸงฉScalable & Sustainable Cross-Chain Solutions
    • ๐Ÿ’ปDevelopment Achievements
    • ๐Ÿ’ Transparency & Open Infrastructure
  • AI-Driven Future and Ecosystem
    • ๐Ÿ“Trading Hub
    • ๐ŸถMeme Economy
    • ๐Ÿ’ธAI-Integrated Wallet
    • ๐Ÿ’ฑPayment System
    • ๐ŸŒฒInfrastructure and Ecosystem
  • Get started
    • ๐Ÿ”‘Login
    • ๐Ÿ’ตDeposit
    • ๐Ÿ“ŠTrade
    • ๐Ÿ’ฐFee Structure
    • โ›ฒWithdrawal
    • ๐Ÿš€Token Listing
      • ๐ŸŒŸBasic mode
      • ๐ŸŽ“Pro mode
    • ๐Ÿ’ณManage Liquidity
    • ๐Ÿ’ธLiquidity Provider
    • โ“Q & A
      • Why Swap Orders Get Cancelled?
  • Developers
    • API
      • Basic
        • get timestamp
        • get chains
        • get assets
        • get asset
      • Market
        • get markets
        • get market
        • get 24hr ticker
        • get extended 24โ€‘hr ticker
        • get kline
        • get swap info
        • get depth
        • get trade history
      • Order
        • get orders
        • get order
        • get trades of order
        • submit spot order
        • cancel spot order
      • Wallet
        • get nonce
        • get balances
      • Broker
        • Get payment address
        • Quote
        • Swap
        • Get agent order
    • Dev SDK
    • Getting Your Proxy Key
  • Risk Management
  • Rewards Program
  • Roadmap
  • Glossary
Powered by GitBook
On this page
  1. Developers
  2. API
  3. Broker

Swap

Submit the swap request. Please note that the txRef is generated before submitting the swap: it is obtained after transferring the assets required for the quote request to the asset-receiving address

PreviousQuoteNextGet agent order

Last updated 23 days ago

Code example

import { brokerClient } from '@delandlabs/hibit-sdk';

const options = {
  network: HibitNetwork.Testnet
};
brokerClient.setOptions(options);

const req = new SwapInput({
      hin: YOUR_AGENT_HIN,
      sourceWalletPublicKey: input.sourceWalletPublicKey,
      sourceWalletAddress: input.sourceWalletAddress,
      txRef: input.txRef,
      sourceChainId: ChainId.fromString(input.sourceChainId),
      sourceAssetType: input.sourceAssetType,
      sourceAsset: input.sourceAsset,
      sourceVolume: BigInt(input.sourceVolume),
      targetChainId: input.targetChainId ? ChainId.fromString(input.targetChainId) : undefined,
      targetAssetType: input.targetAssetType,
      targetAsset: input.targetAsset,
      targetVolume: BigInt(input.targetVolume),
      targetVolumeMin: BigInt(input.targetVolumeMin)
    });
const message = req.tojson();
const signature = ;// call wallet sign message
// signatureSchema: for example -- kaspaschnorr
req.setSignature(signature, input.signatureSchema);
const agentOrderUniqueId = await brokerClient.quote(req);

SDK

Source code

https://github.com/Deland-Labs/hibit-sdk
  • POSTSwap
  • Code example
  • SDK

Swap

post

Submits a swap request between two assets.

Body
hinstringOptional

The HIN of the agent that initiated the swap operation.

sourceWalletPublicKeystring | nullableOptional

The public key of the wallet that initiated the swap operation.

sourceWalletAddressstringOptional

The address of the wallet that initiated the swap operation.

txRefstring | nullableRequired

A unique identifier for the fund transfer tx. For example, the hash of the transaction on the source blockchain.

sourceChainIdstringOptional

The blockchain where the source asset currently resides

sourceAssetTypestringOptional

The type of the source asset (Native, SPL, ERC20, KRC20 etc.). Determines how the asset is identified and processed.

sourceAssetstring | nullableOptional

The identifier for the source asset - either a contract address for tokens or a ticker symbol. Should be null when SourceAssetType is Native (e.g., BTC, ETH, KAS).

sourceVolumestring ยท stringOptional

The amount of source asset to be exchanged/transferred, expressed in the smallest unit of the asset (e.g., satoshi for Bitcoin, wei for Ethereum).

targetChainIdstring | nullableOptional

The destination blockchain for the exchange operation. When null, the system will use the same chain as the source (intra-chain operation).

targetWalletAddressstring | nullableOptional

The destination wallet address where the target assets will be sent. When null, the system will use the source wallet address as the destination.

targetAssetTypestring | nullableOptional

The type of the target asset to receive. When null, the system will use the same asset type as the source.

targetAssetstring | nullableOptional

The identifier for the target asset - either a contract address for tokens or a ticker symbol. Should be null when TargetAssetType is Native (e.g., BTC, ETH, KAS).

targetVolumestring ยท stringOptional

The amount of target asset to be received, expressed in the smallest unit

targetVolumeMinstring ยท stringOptional

The minimum amount of target asset to be received, expressed in the smallest unit

signatureSchemainteger ยท enumOptional

Represents the schema of a wallet signature.

signaturestringOptional

The signature of the swap operation.

Responses
200
OK
400
Bad Request
401
Unauthorized
403
Forbidden
404
Not Found
500
Internal Server Error
501
Not Implemented
post
POST /v1/swap HTTP/1.1
Host: testnetbrokerapi.hibit.app
Content-Type: application/json
Accept: */*
Content-Length: 367

{
  "hin": "text",
  "sourceWalletPublicKey": "text",
  "sourceWalletAddress": "text",
  "txRef": "text",
  "sourceChainId": "text",
  "sourceAssetType": "text",
  "sourceAsset": "text",
  "sourceVolume": "text",
  "targetChainId": "text",
  "targetWalletAddress": "text",
  "targetAssetType": "text",
  "targetAsset": "text",
  "targetVolume": "text",
  "targetVolumeMin": "text",
  "signatureSchema": 1000,
  "signature": "text"
}
{
  "code": 1,
  "message": "text",
  "data": {
    "agentOrderId": "text"
  }
}