`move-to-ts` is a Move-to-TypeScript transpiler and development framework for Aptos.
const {client,account} =...;// Load auto-generated Appconstapp=newApp(client).hippo_tutorial.lend2;// load User and LendingProtocol struct from chainconstuser=awaitapp.loadUser(account.address());constprotocol=awaitapp.loadLendingProtocol(app.moduleAddress,false);// call user_get_limits to compute some info about user's stateconst [isUserHealthy,totalBorrow,totalDeposit] =user.user_get_limits(protocol);console.log(isUserHealthy, totalBorrow, totalDeposit);// make a withdrawalawaitapp.withdraw(account,u64(1000000), [app.FakeBTC.getTag()]);
# From your Move package root folder# Use this step to fetch dependenciesaptosmovecompile# Generate SDK to build/typescript foldermove-to-ts
Interact with contract using generated SDK
const {client,account} =...;// Load auto-generated Appconstapp=newApp(client).hippo_tutorial.lend2;// load User and LendingProtocol struct from chainconstuser=awaitapp.loadUser(account.address());constprotocol=awaitapp.loadLendingProtocol(app.moduleAddress,false);// call user_get_limits to compute some info about user's stateconst [isUserHealthy,totalBorrow,totalDeposit] =user.user_get_limits(protocol);console.log(isUserHealthy, totalBorrow, totalDeposit);// make a withdrawalawaitapp.withdraw(account,u64(1000000), [app.FakeBTC.getTag()]);
Interact with contract using generated CLI utility
When you add the #[cmd] attribute to your Move contract's public entry function, move-to-ts can help you automatically generate the corresponding CLI commandline invocation utility.
For example, for the public entry function admin_add_pool taken from our lending tutorial:
#[cmd(desc=b"Create a new lending pool (admin-only)")]
public entry fun admin_add_pool<CoinType>(admin: &signer, initial_price: u64) acquires LendingProtocol {
The auto-generated CLI utility has the following usage:
$ yarn cli
Usage: yarn cli [options] [command]
Move TS CLI generated by move-to-ts
Options:
-c, --config <path> path to your aptos config.yml (generated with "aptos
init")
-p, --profile <PROFILE> aptos config profile to use (default: "default")
-h, --help display help for command
Commands:
lend2:admin-add-pool <TYPE_CoinType> <initial_price> Create a new lending pool (admin-only)
lend2:admin-init Initialize protocol information (admin-only)
lend2:admin-update-price <TYPE_CoinType> <price> Update price of a particular coin (admin-only)
lend2:borrow <TYPE_CoinType> <amount> Borrow from the CoinType pool. May fail if user exceeds
borrow limit.
...
Debug Move unit tests
// generate TS SDK with unit tests included
move-to-ts -t -n package_name
cd build/typescript
// installs dependency
yarn install
// build project
yarn build
// runs all unit tests
yarn test
// run unit tests from specific file
yarn test move_file_name
Currently it is probably easier to debug move unit tests via move-to-ts than it is using the native Move toolchain, because when a unit test throw error, its stack trace is printed by default and you can very quickly locate where the error has happened.