Skip to main content

Cosmos Chains

Overview​

Astroport runs on two Cosmos chains, Terra and Neutron. Both are CosmWasm chains, so the same tools work on each: a REST (LCD) endpoint for queries from a shell, and CosmJS for queries and transactions from JavaScript.

TerraNeutron
Chain IDphoenix-1neutron-1
Address prefixterraneutron
Fee denomuluna (6 decimals)untrn (6 decimals)
HD path (coin type)m/44'/330'/0'/0/0 (330)m/44'/118'/0'/0/0 (118)
RPChttps://terra-rpc.publicnode.comhttps://neutron-rpc.polkachu.com
REST (LCD)https://terra-rest.publicnode.comhttps://neutron-api.polkachu.com
Explorerterrasco.peCelatone, Mintscan

These are public endpoints run by third parties. They are fine for testing; for production, run your own node or pick a provider from the Cosmos chain registry. Astroport's contract addresses are on the Contract Addresses page. Testnet deployments are not maintained.

Querying with a Shell​

A smart query is a GET request to the REST endpoint with the query JSON encoded in base64:


_1
curl "{REST_ENDPOINT}/cosmwasm/wasm/v1/contract/{CONTRACT_ADDRESS}/smart/{BASE64_QUERY}"

Step 1: Write the Query​

This example asks the Terra Router 2.0 contract for its configuration:


_3
{
_3
"config": {}
_3
}

Step 2: Encode It​


_2
echo -n '{"config":{}}' | base64
_2
# eyJjb25maWciOnt9fQ==

Step 3: Send the Request​


_1
curl "https://terra-rest.publicnode.com/cosmwasm/wasm/v1/contract/terra1txm8xcy8mete9e5zh5ktqr4jm4cq4ja8djttg3zkqll64x4ksq7qknaesf/smart/eyJjb25maWciOnt9fQ=="

The response wraps the contract's answer in data:


_5
{
_5
"data": {
_5
"astroport_factory": "terra14x9fr055x5hvr48hzy2t4q7kvjvfttsvxusa4xsdcy702mnzsvuqprer8r"
_5
}
_5
}

The same request against https://neutron-api.polkachu.com with the Neutron Router 2.0 address (neutron1xuh7nqt486gkvkxdwt773fzs5uptxy0ylzehm3spq7rx8r2kaspqzu0hv6) returns the Neutron factory.

Querying with CosmJS​

CosmWasmClient is a read-only client: it needs no wallet.


_10
import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";
_10
_10
const client = await CosmWasmClient.connect("https://terra-rpc.publicnode.com");
_10
_10
const config = await client.queryContractSmart(
_10
"terra1txm8xcy8mete9e5zh5ktqr4jm4cq4ja8djttg3zkqll64x4ksq7qknaesf",
_10
{ config: {} }
_10
);
_10
_10
console.log(config); // { astroport_factory: "terra14x9fr0..." }

Sending Transactions with CosmJS​

SigningCosmWasmClient signs and broadcasts transactions. Use the address prefix, HD path and gas price of the chain you are on.


_30
import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";
_30
import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";
_30
import { stringToPath } from "@cosmjs/crypto";
_30
import { GasPrice } from "@cosmjs/stargate";
_30
_30
// Terra
_30
const wallet = await DirectSecp256k1HdWallet.fromMnemonic(process.env.MNEMONIC, {
_30
prefix: "terra",
_30
hdPaths: [stringToPath("m/44'/330'/0'/0/0")],
_30
});
_30
const client = await SigningCosmWasmClient.connectWithSigner(
_30
"https://terra-rpc.publicnode.com",
_30
wallet,
_30
{ gasPrice: GasPrice.fromString("0.015uluna") }
_30
);
_30
_30
// Neutron: prefix "neutron", default HD path, GasPrice.fromString("0.0053untrn")
_30
_30
const [{ address: sender }] = await wallet.getAccounts();
_30
_30
// execute(sender, contract, msg, fee, memo, funds)
_30
const result = await client.execute(
_30
sender,
_30
"<contract-address>",
_30
{ some_message: {} },
_30
"auto",
_30
"",
_30
[] // native coins to attach, sorted by denom
_30
);
_30
console.log(result.transactionHash);

Gas prices change over time. Check the chain's current minimum before you rely on the values above.