Integration
HaloTrade smart contracts can be used externally and integrated onto your app with no overhead. In this section we will show all the available methods exposed by the core contacts.
If you want to see the contracts reference instead, you can go to the Contracts section where a full breakdown of the core contracts is explained in detail or you could check out the Github Repo.
All contracts are deployed in all Aura networks (Mainnet, Euphoria and Serenity). You can find the available deployment addresses and code IDs in the Contracts section as well.
API Integration
The API Intergration follows the structure of the CoinGecko Integration API Standards. The API endpoint details necessary for integrating cryptocurrency exchanges, total/circulating supply, and the NFT Marketplace on CoinGecko.
No. | Endpoint | URI |
---|---|---|
1 | /pairs | https://api.halotrade.zone/api/cgk/pairs |
2 | /tickers | https://api.halotrade.zone/api/cgk/tickers |
Contracts Integration
On-chain interaction with the contracts can be easily done with the use of CosmJS, and it can also be done with any other preferred method for building and signing the transactions or queries and interacting directly with the LCD (Light Client Daemon). In this section we will show you how to interact with all the available methods of the deployed contracts with clear examples.
A list of public nodes exposing LCDs, RPCs and gRPCs can be found on the official Aura Network Documentation. Do not use in production environments.
Requirements
To follow the interaction examples shown for the smart contracts you must have the following requirements installed:
The Aura LCD client exposes all the methods you will need to successfully integrate Aura onto your project without any extra work as it behaves as a REST server. You can explore the reference documentation for more details.
The general structure of a transaction is shown below. The transaction parameters in JSON form would be the value of "msg"
in this example.
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
// the JSON encoded send arguments of your transaction
},
"funds": [] // funds to include [optional]
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
To craft a transaction, you would need to populate the fields of the transaction in question (the content within "msg"
) and then proceed to having the transaction signed. So, a fully crafted transaction before signing would look like this:
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"provide_liquidity": {
"assets": [
{
"info": {
"token": {
"contract_addr": "aura..."
}
},
"amount": 10000000000
},
{
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000
}
],
"slippage_tolerance": 5,
"receiver": "aura..."
} },
"funds": [] // funds to include [optional]
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
To send wasm execute transactions to the LCD you must send the fully encoded and signed tx bytes and mode as the request body shown below to the Cosmos BroadcastTx endpoint on the LCD client.
{
"tx_bytes": "string",
"mode": "BROADCAST_MODE_UNSPECIFIED"
}
To query contracts, you can just send your query to the Wasm SmartContractState.
As for querying transactions, you can use the Cosmos GetTxsEvent endpoint on the same LCD client or you can also use Horoscope which can be easier to integrate on some cases and is as reliable as the LCD client itself.
For a full reference on the available methods, you can go to the Contracts section.
Factory
CosmJS
To interact with the Factory
contract using JS, you can see the following examples for the available methods.
- InstantiateMsg
- UpdateConfig
- CreatePair
- AddNativeTokenDecimals
- Config
- Pair
- Pairs
- NativeTokenDecimals
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const deployerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const deployerClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, deployerWallet, {gasPrice});
const deployerAccount = (await deployerWallet.getAccounts())[0];
// ********************
// INSTANTIATE CONTRACT
// ********************
// prepare instantiate message
const haloFactoryInstantiateMsg = {
"pair_code_id": pair_code_id,
"token_code_id": token_code_id,
}
// Execute instantiate contract
await deployerClient.instantiate(
deployerAccount.address,
Number(contract_code_id), // the code id of halo factory contract
haloFactoryInstantiateMsg,
"instantiation halo_factory contract",
"auto",
);
// print out transaction's info
console.log("TransactionHash: ", instantiateResponse.transactionHash);
console.log("ContractAddress: ", instantiateResponse.contractAddress);
console.log("GasWanted / GasUsed: ", instantiateResponse.gasUsed, " / ", instantiateResponse.gasWanted);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const deployerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const deployerClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, deployerWallet, {gasPrice});
const deployerAccount = (await deployerWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// prepare execute message
const updateConfigMsg = {
"update_config": {
"owner": "aura100000000000000000000000NewOwnerAddress",
"token_code_id": 321,
"pair_code_id": 321
}
}
// Execute contract
let executeResponse = await deployerClient.execute(
deployerAccount.address,
contractAddress,
updateConfigMsg,
"auto",
"update config",
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const deployerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const deployerClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, deployerWallet, {gasPrice});
const deployerAccount = (await deployerWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// prepare execute message
const createPairMsg = {
"create_pair": {
"asset_infos": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
],
"requirements": {
"whitelist": [
"aura...",
"aura..."
],
"first_asset_minimum": 10000,
"second_asset_minimum": 20000
},
"commission_rate": "0.003",
"lp_token_info": {
"lp_token_name": "AURA_HALO_LP",
"lp_token_symbol": "AURA_HALO_LP",
}
},
}
// Execute contract
let executeResponse = await deployerClient.execute(
deployerAccount.address,
contractAddress,
createPairMsg,
"auto",
"create pair",
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const deployerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const deployerClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, deployerWallet, {gasPrice});
const deployerAccount = (await deployerWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// prepare execute message
const addNativeTokenDecimalsMsg = {
"add_native_token_decimals": {
"denom": "uaura",
"decimals": 6,
}
}
// Execute contract
let executeResponse = await deployerClient.execute(
deployerAccount.address,
contractAddress,
addNativeTokenDecimalsMsg,
"auto",
"add new native token decimals",
[coin(1, "uaura")],
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const configMsg = {
"config": {}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, configMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const pairMsg = {
"pair": {
"asset_infos": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
]
}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, pairMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const pairsMsg = {
"pairs": { }
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, pairsMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const nativeTokenDecimalsMsg = {
"native_token_decimals": {
"denom": "uaura",
},
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, nativeTokenDecimalsMsg);
// print out the query response
console.log(queryResponse);
LCD Client
To use the available methods exposed by the Factory
contract you can use this as reference:
- InstantiateMsg
- UpdateConfig
- CreatePair
- AddNativeTokenDecimals
- Config
- Pair
- Pairs
- NativeTokenDecimals
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgInstantiateContract",
"sender": "aura1...",
"admin": "",
"code_id": "000",
"label": "factory",
"msg": {
{
"pair_code_id": 123,
"token_code_id": 123
}
},
"funds": [
{
"denom": "uaura",
"amount": "4000"
}
]
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"update_config": {
"owner": "aura1...",
"token_code_id": 321,
"pair_code_id": 321
}
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"create_pair": {
"asset_infos": [
{
"token": {
"contract_addr": "aura1..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
],
"requirements": {
"whitelist": [
"aura1...",
"aura1..."
],
"first_asset_minimum": 10000,
"second_asset_minimum": 20000
},
"commission_rate": "0.003",
"lp_token_info": {
"lp_token_name": "AURA_HALO_LP",
"lp_token_symbol": "AURA_HALO_LP"
}
}
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"add_native_token_decimals": {
"denom": "uaura",
"decimals": 6
}
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"config": {}
}
{
"pair": {
"asset_infos": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
]
}
}
{
"pairs": {}
}
{
"native_token_decimals": {
"denom": "uaura"
}
}
Router
CosmJS
To interact with the Router
contract using JS, you can see the following examples for the available methods.
- InstantiateMsg
- ExecuteSwapOperations
- Config
- SimulateSwapOperations
- ReverseSimulateSwapOperations
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const factoryContractAddress = "aura100000000000000000000000000000000000000000000000HaloFactory";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const deployerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const deployerClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, deployerWallet, {gasPrice});
const deployerAccount = (await deployerWallet.getAccounts())[0];
// ********************
// INSTANTIATE CONTRACT
// ********************
// prepare instantiate message
const haloRouterInstantiateMsg = {
"halo_factory": factoryContractAddress,
}
// Execute instantiate contract
await deployerClient.instantiate(
deployerAccount.address,
Number(contract_code_id), // the code id of halo router contract
haloRouterInstantiateMsg,
"instantiation halo_router contract",
"auto",
);
// print out transaction's info
console.log("TransactionHash: ", instantiateResponse.transactionHash);
console.log("ContractAddress: ", instantiateResponse.contractAddress);
console.log("GasWanted / GasUsed: ", instantiateResponse.gasUsed, " / ", instantiateResponse.gasWanted);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const routerContractAddress = "aura1000000000000000000000000000000000000000000000000HaloRouter";
const tokenAContractAddress = "aura10000000000000000000000000000000000000000000000000000tokenA";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
const userAccount = (await userWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// we must define the hook cw20 message first
const hookMsg = {
"execute_swap_operations": {
"operations": [
{
"offer_asset_info": {
"token": {
"contract_addr": tokenAContractAddress,
}
},
"ask_asset_info": {
"native_token": {
"denom": "uaura",
}
},
},
],
},
}
// prepare execute message
const executeSendMsg = {
"send": {
"contract": routerContractAddress,
"amount": "100000000",
"msg": Buffer.from(JSON.stringify(hookMsg)).toString('base64')
}
}
// Execute contract
let executeResponse = await userClient.execute(
userAccount.address,
tokenAContractAddress,
executeSendMsg,
"auto",
"swap token",
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura1000000000000000000000000000000000000000000000000HaloRouter";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const configMsg = {
"config": {}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, configMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura1000000000000000000000000000000000000000000000000HaloRouter";
const tokenAContractAddress = "aura10000000000000000000000000000000000000000000000000000tokenA";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const simulateSwapMsg = {
"simulate_swap_operations": {
"offer_amount": 10000,
"operations": [
{
"offer_asset_info": {
"token": {
"contract_addr": tokenAContractAddress,
}
},
"ask_asset_info": {
"native_token": {
"denom": "uaura"
}
},
},
],
},
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, simulateSwapMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura1000000000000000000000000000000000000000000000000HaloRouter";
const tokenAContractAddress = "aura10000000000000000000000000000000000000000000000000000tokenA";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const reverseSimulateSwapMsg = {
"reverse_simulate_swap_operations" {
"ask_amount": 10000,
"operations": [
{
"offer_asset_info": {
"token": {
"contract_addr": tokenAContractAddress,
}
},
"ask_asset_info": {
"native_token": {
"denom": "uaura",
}
},
},
],
},
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, reverseSimulateSwapMsg);
// print out the query response
console.log(queryResponse);
LCD Client
To use the available methods exposed by the Router
contract you can use this as reference:
- InstantiateMsg
- ExecuteSwapOperations
- Config
- SimulateSwapOperations
- ReverseSimulateSwapOperations
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgInstantiateContract",
"sender": "aura1...",
"admin": "",
"code_id": "000",
"label": "factory",
"msg": {
"halo_factory": "aura1...", // The address of the factory contract
},
"funds": [
{
"denom": "uaura",
"amount": "4000"
}
]
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"execute_swap_operations" {
"operations": [
{
"offer_asset_info": {
"token": {
"contract_addr": "aura1...",
}
},
"ask_asset_info": {
"native_token": {
"denom": "uaura"
}
},
},
],
"minimum_receive": "0",
"to": "aura1...",
},
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
Where:
operations
is the list of swap operations. Each operation contains the offer asset and the ask asset. The offer asset is the asset that the user wants to swap. The ask asset is the asset that the user wants to receive.minimum_receive
is the minimum amount of the ask asset that the user wants to receive. If the amount of the ask asset is less than the minimum amount, the swap operation will fail.to
is the address that the user wants to receive the ask asset.
{
"config" {}
}
{
"simulate_swap_operations": {
"offer_amount": 10000,
"operations": {[
"offer_asset_info": {
"token": {
"contract_addr": "aura...",
}
},
"ask_asset_info": {
"native_token": {
"denom": "uaura"
}
},
]},
},
}
{
"reverse_simulate_swap_operations": {
"ask_amount": 10000,
"operations": {[
"offer_asset_info": {
"token": {
"contract_addr": "aura...",
}
},
"ask_asset_info": {
"native_token": {
"denom": "uaura"
}
},
]},
},
}
Pair
CosmJS
To interact with the Pair
contract using JS, you can see the following examples for the available methods.
- InstantiateMsg
- ProvideLiquidity
- WithdrawLiquidity
- Swap
- Pair
- Pool
- Simulation
- ReverseSimulation
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const deployerWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const deployerClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, deployerWallet, {gasPrice});
const deployerAccount = (await deployerWallet.getAccounts())[0];
// ********************
// INSTANTIATE CONTRACT
// ********************
// prepare instantiate message
const haloPairInstantiateMsg = {
"asset_infos": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
],
"token_code_id": 123,
"asset_decimals": [ 6, 6 ],
"requirements": {
"whitelist": [
"aura...",
"aura..."
],
"first_asset_minimum": 10000,
"second_asset_minimum": 20000
},
"commission_rate": "0.003",
"lp_token_info": {
"lp_token_name": "AURA_HALO_LP",
"lp_token_symbol": "AURA_HALO_LP",
},
}
// Execute instantiate contract
await deployerClient.instantiate(
deployerAccount.address,
Number(contract_code_id), // the code id of halo pair contract
haloFactoryInstantiateMsg,
"instantiation halo_pair contract",
"auto",
);
// print out transaction's info
console.log("TransactionHash: ", instantiateResponse.transactionHash);
console.log("ContractAddress: ", instantiateResponse.contractAddress);
console.log("GasWanted / GasUsed: ", instantiateResponse.gasUsed, " / ", instantiateResponse.gasWanted);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
const tokenAContractAddress = "aura10000000000000000000000000000000000000000000000000000tokenA";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
const userAccount = (await userWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// you must inscrease allowance for contractAddress in tokenAContractAddress
// prepare inscrease allowance message
let increaseAllowMsg = {
"increase_allowance": {
"spender": contractAddress,
"amount": "500000000",
},
};
// increase allowance
let increaseAllowResponse = await userClient.execute(
userAccount.address,
tokenAContractAddress,
increaseAllowMsg,
"auto",
"increase allowance",
);
// prepare execute message
const provideLiquidityMsg = {
"provide_liquidity" {
"assets": [
{
"info": {
"token": {
"contract_addr": tokenAContractAddress,
}
},
"amount": 10000000000,
},
{
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
],
"slippage_tolerance": 5,
"receiver": "aura...",
}
}
// Execute contract
let executeResponse = await userClient.execute(
userAccount.address,
contractAddress,
provideLiquidityMsg,
"auto",
"provide liquidity",
[coin(500000000, "uaura")]
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const pairContractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
const lpTokenContractAddress = "aura1000000000000000000000000000000000000000000000000000lpToken";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
const userAccount = (await userWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// we must define the hook cw20 message first
const hookMsg = {
"withdraw_liquidity": {}
}
// prepare execute message
const executeSendMsg = {
"send": {
"contract": pairContractAddress,
"amount": "100000000",
"msg": Buffer.from(JSON.stringify(hookMsg)).toString('base64')
}
}
// Execute contract
let executeResponse = await userClient.execute(
userAccount.address,
lpTokenContractAddress,
executeSendMsg,
"auto",
"withdraw liquidity",
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const pairContractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
const tokenAContractAddress = "aura10000000000000000000000000000000000000000000000000000tokenA";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
const userAccount = (await userWallet.getAccounts())[0];
// ****************
// EXECUTE CONTRACT
// ****************
// we must define the hook cw20 message first
const hookMsg = {
"swap": {
"offer_asset": {
"info": {
"token": {
"contract_addr": tokenAContractAddress,
}
},
"amount": 10000000000,
},
},
}
// prepare execute message
const executeSendMsg = {
"send": {
"contract": pairContractAddress,
"amount": "10000000000",
"msg": Buffer.from(JSON.stringify(hookMsg)).toString('base64')
}
}
// Execute contract
let executeResponse = await userClient.execute(
userAccount.address,
tokenAContractAddress,
executeSendMsg,
"auto",
"swap token",
);
// print out the transaction's info
console.log("TransactionHash: ", executeResponse.transactionHash);
console.log("GasWanted / gasUsed: ", executeResponse.gasWanted, " / ", executeResponse.gasUsed);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const pairMsg = {
"pair": {}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, pairMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const poolMsg = {
"pool": {}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, poolMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
const tokenAContractAddress = "aura10000000000000000000000000000000000000000000000000000tokenA";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const simulationMsg = {
"simulation": {
"offer_asset": {
"info": {
"token": {
"contract_addr": tokenAContractAddress,
}
},
"amount": 10000000000,
}
}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, simulationMsg);
// print out the query response
console.log(queryResponse);
const fs = require('fs/promises');
const { SigningCosmWasmClient } = require("@cosmjs/cosmwasm-stargate");
const { DirectSecp256k1HdWallet } = require("@cosmjs/proto-signing");
const { GasPrice } = require("@cosmjs/stargate");
// config chain
const RPCEndpoint = "https://rpc..aura.network";
const prefix = "aura";
const denom = "uaura";
// you must provide the address of the contract you want to execute here
const contractAddress = "aura100000000000000000000000000000000000000000000000000HaloPair";
// ***************************
// SETUP INFORMATION FOR USERS
// ***************************
// connect deployer wallet to chain and get admin account
const userWallet = await DirectSecp256k1HdWallet.fromMnemonic(
(await readFile("./sample.mnemonic.key")).toString(),
{
prefix: prefix,
}
);
// config gas price
const gasPrice = GasPrice.fromString(`0.025${denom}`);
const userClient = await SigningCosmWasmClient.connectWithSigner(RPCEndpoint, userWallet, {gasPrice});
// ********************
// QUERY CONTRACT
// ********************
// prepare query message
const reverseSimulationMsg = {
"reverseSimulation": {
"ask_asset": {
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
}
}
// Query contract
const queryResponse = await userClient.queryContractSmart(contractAddress, reverseSimulationMsg);
// print out the query response
console.log(queryResponse);
LCD Client
To use the available methods exposed by the Pair
contract you can use this as reference:
- InstantiateMsg
- ProvideLiquidity
- WithdrawLiquidity
- Swap
- Pair
- Pool
- Simulation
- ReverseSimulation
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgInstantiateContract",
"sender": "aura1...",
"admin": "",
"code_id": "000",
"label": "factory",
"msg": {
"asset_infos": [
{
"token": {
"contract_addr": "aura..."
}
},
{
"native_token": {
"denom": "uaura"
}
}
],
"token_code_id": 123,
"asset_decimals": [ 6, 6 ],
"requirements": {
"whitelist": [
"aura...",
"aura..."
],
"first_asset_minimum": 10000,
"second_asset_minimum": 20000
},
"commission_rate": "0.003",
"lp_token_info": {
"lp_token_name": "AURA_HALO_LP",
"lp_token_symbol": "AURA_HALO_LP",
},
},
"funds": [
{
"denom": "uaura",
"amount": "4000"
}
]
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
Where:
asset_infos
is the list of assets in the pair (The pair can be token<->native, token-token or native-native).token_code_id
is the source code id ofhalo-token
contract.asset_decimals
is the list of decimals of assets in the pair.requirements
is the whitelist wallet address list and requirements for providing liquidity for the first time.commission_rate
is the commission rate of the pair.lp_token_info
is the information of the LP token.
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"provide_liquidity" {
"assets": [
{
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
},
{
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
],
"slippage_tolerance": 5,
"receiver": "aura...",
},
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"withdraw_liquidity": {}
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
{
"body": {
"messages": [
{
"@type": "/cosmwasm.wasm.v1.MsgExecuteContract",
"sender": "aura1...",
"contract": "aura1...",
"msg": {
"swap": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "aura1...",
}
},
"amount": 10000000000,
},
"belief_price": "0",
"max_spread": "0",
"to": "aura1...",
},
},
"funds": []
}
],
"memo": "",
"timeout_height": "0",
"extension_options": [],
"non_critical_extension_options": []
},
"auth_info": {
"signer_infos": [],
"fee": {
"amount": [
{
"denom": "uaura",
"amount": "200"
}
],
"gas_limit": "200000",
"payer": "",
"granter": ""
}
},
"signatures": []
}
Where:
offer_asset
is the asset that the sender wants to swap.belief_price
is the belief price of the swap.max_spread
is the maximum spread of the swap.
{
"pair": {}
}
{
"pool": {}
}
{
"simulation": {
"offer_asset": {
"info": {
"token": {
"contract_addr": "aura...",
}
},
"amount": 10000000000,
}
}
}
{
"reverseSimulation": {
"ask_asset": {
"info": {
"native_token": {
"denom": "uaura"
}
},
"amount": 500000000,
}
}
}