Homa Liquid Staking
To interact with Acala or Karura from Javascript you can use @polkadot/api along with @acala-network/api.
For those looking to stake DOT or unstake LDOT, we also offer the Homa SDK.
Homa Example
The following example demonstrates how to utilize the Homa SDK and the Polkadot API for staking DOT and unstaking LDOT.
You can fork the live example on replit and run the example yourself.
To run the example on replit, you neeed to first fork it, otherwise it will only show an empty webview page.
Actual result will be logged to console instead of the webview page, only after you fork it.
prepare env, api, and sdk
first import deps
const { fetchConfig, setupWithServer } = require('@acala-network/chopsticks')
const { ApiPromise, WsProvider } = require('@polkadot/api')
const { Homa, Wallet } = require('@acala-network/sdk')
const { createTestKeyring } = require('@polkadot/keyring')use Chopsticks to fork mainnet to a local testnet
const acalaConfig = await fetchConfig('acala')
acalaConfig.port = 8111 // set the port
acalaConfig.block = 4286000
acalaConfig.db = './db.sqlite'
const { chain, listenPort, close } = await setupWithServer(acalaConfig)
// This server can be accessed at wss://acalajs-examples--xlc.repl.co/
// Use https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Facalajs-examples--xlc.repl.co to connect to this testnet
console.log('Chopsticks is running on port', listenPort)setup Acala api connect to the local testnet
add a couple helpers
setup wallet sdk and homa sdk
query some info
stake DOT
unstake LDOT
There are number of ways to unstake LDOT / convert it back to DOT
Slow unstake by wait for 28 days.
Use fast redeem by matching with new stakers. A fast redeem fee is charged. This is only available if there are DOT in the pending pool.
Use the Taiga tDOT pool to swap LDOT to DOT. A swap fee is charged. The swap rate depends on the pool balance
slow unstake
swap with taiga tDOT pool
use aggregatedDex to perform swap, which allow multiple step swap with both Taiga pool and Acala Dex pool in a single tx
clean up
shutdown the Chopsticks server
More References
Last updated
Was this helpful?