Tutorial: How to collect fees from the Astroport Maker contract using Terra.js

1. Set up

Prerequisites

Installing Terra.js

cd Desktop
mkdir maker-tutorial
cd maker-tutorial
npm init
npm install --save @terra-money/terra.js
export NODE_OPTIONS=--openssl-legacy-provider

Getting started with Terra.js

  • LCDClient to connect to the Terra blockchain
  • MnemonicKey to sign and confirm transactions
  • MsgExecuteContract to process and execute messages
// 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);
// ** SET UP ** //// required modulesconst { 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);

2. Collecting fees from the Maker contract

// maker testnet address
const contract_address = 'terra146ffs60x8seza3cq9a447mhw0zqeylkj37ye4uj7rl2uwhvgq89sts2ess'
// maker collect function
const execute = new MsgExecuteContract(
wallet.key.accAddress, // sender
contract_address, // contract account address
{
"collect": {
"assets": [
{
"info": {
"token": {
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
}
}
},
{
"info": {
"native_token": {
"denom": "uluna"
}
}
}
],
}
}, // 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
C3C3C6C35C5F9C49CECD4C6A5CC2BD79884E0CACC08D5D68732916EAF22C8AFA

3. Maker Queries

config

// query config params
const query = terra.wasm.contractQuery(
contract_address,
{
"config": {}
} // query msg
).then(result => { console.log(result) });
node index.js
{
owner: 'terra190fxpjfkp6cygr2k9unzjurq42dyehqd579h5j',
astro_token_contract: 'terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv',
factory_contract: 'terra1z3y69xas85r7egusa0c7m5sam0yk97gsztqmh8f2cc6rr4s4anysudp7k0',
staking_contract: 'terra19t8ffmz6q2rdm3rllyksd6sex6n650a4anttzzvz9mf8mqr4nkrq44cyu6',
governance_contract: null,
governance_percent: '0',
max_spread: '0.5',
remainder_reward: '759941404',
pre_upgrade_astro_amount: '759941404'
}

balances

// query balances
const query = terra.wasm.contractQuery(
contract_address,
{
"balances": {
"assets": [
{
"token": {
"contract_addr": "terra167dsqkh2alurx997wmycw9ydkyu54gyswe3ygmrs4lwume3vmwks8ruqnv"
}
},
{
"native_token": {
"denom": "uluna"
}
}
],
}
} // query msg
).then(result => { console.log(result) });
node index.js
{ balances: [ { info: [Object], amount: '759941404' } ] }

4. Congrats! You’ve completed the Maker contract tutorial!

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