Tutorial: how to interact with the Astroport Staking contract using Terra.js

  • Constant Product Pools: 0.3% Total Fee — 1/3 goes to ASTRO stakers
  • Stableswap Pools: 0.05% Total Fee — 1/2 goes to ASTRO stakers

1. Prerequisites

Terra.js

// required modules
const { LCDClient, MnemonicKey, MsgExecuteContract } = require('@terra-money/terra.js');
// connecting to terra blockchain
const terra = new LCDClient({
URL: 'https://pisco-lcd.terra.dev',
chainID: 'pisco-1',
});
// wallet information
const mk = new MnemonicKey({
mnemonic: ''
});
const wallet = terra.wallet(mk);

ASTRO Tokens

2. Set up

const staking_address = "terra19t8ffmz6q2rdm3rllyksd6sex6n650a4anttzzvz9mf8mqr4nkrq44cyu6";const astro_address = "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv";const xastro_address = "terra1ctzthkc0nzseppqtqlwq9mjwy9gq8ht2534rtcj3yplerm06snmqfc5ucr";

3. Staking ASTRO

const execute = new MsgExecuteContract(
wallet.key.accAddress, // sender
astro_address, // contract address
{
"send": {
"contract": "terra19t8ffmz6q2rdm3rllyksd6sex6n650a4anttzzvz9mf8mqr4nkrq44cyu6",
"amount": "10000000",
"msg": "ewogICJlbnRlciI6IHt9Cn0="
}
}, // handle msg
);
const start = async function () {
const executeTx = await wallet.createAndSignTx({
msgs: [execute]
})
.then(tx => terra.tx.broadcast(tx))
.then(result => {
console.log(result.txhash)
});
}
start();
node index.js
3775C58F9EB0C54CC83A7906EC62808319C87531ED5AD75CF2173E9A9FD4FE5B

4. Unstaking xASTRO

const execute = new MsgExecuteContract(
wallet.key.accAddress, // sender
xastro_address, // contract address
{
"send": {
"contract": "terra19t8ffmz6q2rdm3rllyksd6sex6n650a4anttzzvz9mf8mqr4nkrq44cyu6",
"amount": "10000000",
"msg": "ewogICJsZWF2ZSI6IHt9Cn0"
}
}, // handle msg
);
const start = async function () {
const executeTx = await wallet.createAndSignTx({
msgs: [execute]
})
.then(tx => terra.tx.broadcast(tx))
.then(result => {
console.log(result.txhash)
});
}
start();
node index.js
1EA7076D517E17A4932F3C9DFF766C90B2261A2560A4EEB4D4BAB8C56DA6A488

5. Querying the Staking contract

node index.js

Config

// query config paramsconst query = terra.wasm.contractQuery(
staking_address,
{
"config": {}
} // query msg
).then(result => { console.log(result) });
{
deposit_token_addr: 'terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv',
share_token_addr: 'terra1ctzthkc0nzseppqtqlwq9mjwy9gq8ht2534rtcj3yplerm06snmqfc5ucr'
}

Total Shares

// query config paramsconst query = terra.wasm.contractQuery(
staking_address,
{
"total_shares": {}
} // query msg
).then(result => { console.log(result) });
871578645933

Total Deposit

// query config paramsconst query = terra.wasm.contractQuery(
staking_address,
{
"total_deposit": {}
} // query msg
).then(result => { console.log(result) });
871578645933

6. Congrats! You have completed the tutorial on the Astroport Staking contract!

DISCLAIMER

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Astroport

Astroport

An automated, decentralised exchange protocol on the Terra blockchain. http://astroport.fi