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.
| Terra | Neutron | |
|---|---|---|
| Chain ID | phoenix-1 | neutron-1 |
| Address prefix | terra | neutron |
| Fee denom | uluna (6 decimals) | untrn (6 decimals) |
| HD path (coin type) | m/44'/330'/0'/0/0 (330) | m/44'/118'/0'/0/0 (118) |
| RPC | https://terra-rpc.publicnode.com | https://neutron-rpc.polkachu.com |
| REST (LCD) | https://terra-rest.publicnode.com | https://neutron-api.polkachu.com |
| Explorer | terrasco.pe | Celatone, 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:
_1curl "{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
_2echo -n '{"config":{}}' | base64_2# eyJjb25maWciOnt9fQ==
Step 3: Send the Request
_1curl "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.
_10import { CosmWasmClient } from "@cosmjs/cosmwasm-stargate";_10_10const client = await CosmWasmClient.connect("https://terra-rpc.publicnode.com");_10_10const config = await client.queryContractSmart(_10 "terra1txm8xcy8mete9e5zh5ktqr4jm4cq4ja8djttg3zkqll64x4ksq7qknaesf",_10 { config: {} }_10);_10_10console.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.
_30import { SigningCosmWasmClient } from "@cosmjs/cosmwasm-stargate";_30import { DirectSecp256k1HdWallet } from "@cosmjs/proto-signing";_30import { stringToPath } from "@cosmjs/crypto";_30import { GasPrice } from "@cosmjs/stargate";_30_30// Terra_30const wallet = await DirectSecp256k1HdWallet.fromMnemonic(process.env.MNEMONIC, {_30 prefix: "terra",_30 hdPaths: [stringToPath("m/44'/330'/0'/0/0")],_30});_30const 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_30const [{ address: sender }] = await wallet.getAccounts();_30_30// execute(sender, contract, msg, fee, memo, funds)_30const result = await client.execute(_30 sender,_30 "<contract-address>",_30 { some_message: {} },_30 "auto",_30 "",_30 [] // native coins to attach, sorted by denom_30);_30console.log(result.transactionHash);
Gas prices change over time. Check the chain's current minimum before you rely on the values above.