StxCity SDK is a powerful and easy-to-use library for interacting with the StxCity Protocol. It provides a set of tools to seamlessly integrate StxCity functionality into your applications.
Install the StxCity SDK using npm:
npm install stxcity-sdk
Here's a step-by-step guide to implement the StxCity SDK in your project:
import { StxCitySDK } from 'stxcity-sdk';
const stxcityConfig = {
HIRO_API_KEY: "", // get it from https://platform.hiro.so/
STXCITY_API_HOST: 'https://stx.city',
STACKS_NETWORK_API_HOST: 'https://api.mainnet.hiro.so'
}
const stxcitySDK = new StxCitySDK(new StacksMainnet(), stxcityConfig)
STXCITY_API_HOST="https://stx.city"
STACKS_NETWORK_API_HOST="https://api.mainnet.hiro.so"
HIRO_API_KEY="" // get it from https://platform.hiro.so/
and then initialize the SDK like this:
const stxcitySDK = new StxCitySDK(new StacksMainnet())
try {
const params: BuyBondingTokenParams = {
stxAmount: 100, // Replace with actual amount
dexContractId: 'dexId', // Replace with actual dex contract ID
tokenContractId: 'tokenContractId', // Replace with actual token contract ID
tokenSymbol: "symboltoken", // Replace with actual token symbol
senderAddress: "ST3JH3Y...XYZ", // Replace with sender address
slippage: 50, // Replace with your slippage
onFinish: (data) => {
console.log("Buy token:", data);
},
onCancel: () => {
console.log("Buy token canceled");
},
};
await StxCitySDK.buyBondingToken(params);
} catch (error) {
console.error("Error buying bonding token:", error);
}
Note: Already check valid bonding curve contract inside this function
try {
const params: SellBondingTokenParams = {
tokenAmount: 2000000, // Replace with actual amount token
dexContractId: 'dexId', // Replace with actual dex contract ID
tokenContractId: 'tokenContractId', // Replace with actual token contract ID
tokenSymbol: 'symboltoken', // Replace with actual token symbol
senderAddress: "ST3JH3Y...XYZ", // Replace with sender address
slippage: 50, // Replace with your slippage
onFinish: (data) => {
console.log("Sell token success:", data);
},
onCancel: () => {
console.log("Sell token canceled");
},
};
await StxCitySDK.sellBondingToken(params);
} catch (error) {
console.error("Error selling bonding token:", error);
}
Note: Already check valid bonding curve contract inside this function
Check if the bonding curve contract is valid to avoid scam/fake tokens.
const isValid = await StxCitySDK.checkValidBondingToken('dexContractId', 'tokenContractId');
let page = 1;
let limit = 40
const bondingTokenData = await StxCitySDK.getBondingToken(page, limit);
limit
max is 100
let params:SearchTokenParams = {
keyword : 'searchKeyowrd', // Replace with actual search keyword
tokenContract: 'xxxxx-stxcity' // Replace with actual token contract ID you want to search
}
const data = await StxCitySDK.searchToken(params)
-
The StxCity SDK is provided "as is" without any warranty. Use it at your own risk.
-
There are many malicious or fake bonding curve contracts on the Stacks blockchain. Please make sure you are using the correct bonding curve contract or user wallet can be drained.
-
Call
checkValidBondingToken
function to check if the bonding curve contract is valid.
The following public methods are available in the StxCitySDK
class:
Buys a bonding token with the specified parameters.
Sells a bonding token with the specified parameters.
Fetches bonding token data for the specified page and limit.
Searches for tokens based on the provided parameters.
The following types and interfaces are exported from the types.ts
file:
export interface StxCityContext {
validAPIKey: boolean;
network: StacksNetwork;
}
export interface BondingTokenItem {
id: number;
token_contract: string;
dex_contract: string;
progress: number;
name: string;
tx_id: string;
symbol: string;
decimals: number;
supply: number;
logo_url: string;
holders: number;
deployed_at: Date;
stx_paid: number;
description: string;
xlink: string;
homepage: string;
telegram: string;
discord: string;
status: string;
target_AMM: string;
chat_count: number;
txs_count: number;
trading_volume: number;
target_stx: number;
price?: number;
price_24h_changes?: number;
token_to_dex?: number;
token_to_deployer?: number;
stx_to_dex?: number;
stx_buy_first_fee?: number;
}
export interface NormalTokenItem {
contract_id: string;
name: string;
logo_url: string;
symbol: string;
homepage: string;
supply: number;
decimals: number;
holders: number;
tx_id: string;
deployed_at: Date;
}
export interface BondingTokenData {
trending: BondingTokenItem[];
new: BondingTokenItem[];
completed: BondingTokenItem[];
all: BondingTokenItem[];
total: number;
page: number;
limit: number;
}
export interface BuyBondingTokenParams {
stxAmount: number;
dexContractId: string;
tokenContractId: string;
tokenSymbol: string;
senderAddress: string;
slippage: number;
stacksProvider?: StacksProvider;
onFinish?: (data: any) => void;
onCancel?: () => void;
}
export interface SellBondingTokenParams {
tokenAmount: number;
dexContractId: string;
tokenContractId: string;
tokenSymbol: string;
senderAddress: string;
slippage: number;
stacksProvider?: StacksProvider;
onFinish?: (data: any) => void;
onCancel?: () => void;
}
export interface SearchTokenType {
ads_tokens: BondingTokenItem[];
bonding_curve: BondingTokenItem[];
normal: NormalTokenItem[];
}
export type SearchTokenParams = {
keyword?: string;
tokenContract?: string;
};
If you encounter any issues while using the StxCity SDK, please check the following:
- Make sure you have the latest version of the SDK installed.
- Check that you're using a valid Stacks address for the
senderAddress
parameter.
This project is licensed under the MIT License - see the LICENSE file for details.