Swap

API details

Swap supports both intra-chain and cross-chain assets. As long as the trading pair is supported by Hibit, it can be used for swapping. 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

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
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"
  }
}

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

Last updated