Hallswap API
Hallswap API allows developers to access liquidity on Hallswap supported chains. Supported chains: Injective, Sei, Archway, Oraichain, Neutron, Terra, Migaloo, Chihuahua
Last updated
import { MsgExecuteContract } from "cosmes/client";
import { CosmosBaseV1beta1Coin } from "cosmes/protobufs";
import { MnemonicWallet } from "cosmes/wallet";
// Simulate swapping 13 USDT to INJ at 1.0% slippage in Injective
const res = await fetch(
"https://swap.coinhall.org/v1/swap?chainId=injective-1&from=peggy0xdAC17F958D2ee523a2206206994597C13D831ec7&to=inj&amount=13000000&slippageBps=100"
);
const {
expectedReturn,
minimumReceive,
contractInput,
route,
} = await res.json();
console.log("Expected return amount", expectedReturn);
console.log("Minimum amount to be received", minimumReceive);
console.log("Route:", route);
// Execute the swap
const wallet = new MnemonicWallet({ /* redacted for brevity */ });
const msgs = [
new MsgExecuteContract({
sender: wallet.address,
contract: contractInput.address,
msg: contractInput.executeMsg,
funds: contractInput.funds,
}),
];
const tx = await wallet.broadcastTxSync({ msgs });
console.log(tx);// The query parameters of the request
type Request = {
chainId: string;
to: string;
from: string;
amount: string;
slippageBps: string;
};
// The JSON response from the API
type Response = {
expectedReturn: string;
minimumReceive: string;
contractInput: {
address: string;
executeMsg: JSON;
funds: {
denom: string;
amount: string;
}[];
};
route: {
returnAsset: {
symbol: string;
icon?: string | undefined;
};
dex: string;
}[];
};