Hello APTOS

Norman Fung
5 min readOct 21, 2022

--

This is to supplement Aptos quick start. The intention is to put all the baby steps a python dev need to get started on aptos in one place

  • check wallet balance (Not just total account APT balance, but also coin balances)
  • fetch transactions under given wallet addresses (This is not in our official quick start samples)
  • fund it from devnet faucet
  • deploy a MOVE contract
  • interact with it
  • fetch transaction details/status with transaction hash
  • then check things from Aptos explorer.
  • know where you can bridge money in/out aptos, where to go if you want to do swaps or yield farming
  • Similarities between router smart contracts from cronos/EVM and those in aptos

I am not going to go into how to open Pontem or Petra wallet.

And the baby steps begins …

  1. Check wallet balance and fund your devnet wallet from aptos faucet.

Pip install aptos_sdk. btw, it’s not pypy compatible (but to be fair pypy hate many things): https://forum.aptoslabs.com/t/pypy-install-aptos-sdk-on-windows-failed-on-pynacl/128945/4

Below shows you how to construct Account object from wallet address and private key, this was missing from Aptos “Your First Transaction”, so I thought this would be handy.

Note “acc_balance” above is total account balance in APT. If you want individual coinbalance, use rest_client.account_resource

Now how to find “resource_type”? dex screener come to rescue:

Just select any USDC pool for example, click on USDC lower right:

This will lead you to https://explorer.aptoslabs.com/account/0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa/resources

Under “Resources” tab, you will find:

  • resource_type: 0x1::coin::CoinInfo<0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC>
  • token address: 0xf22bede237a07e121b56d91a491eb7bcdfd1f5907926a9e58338f964a01b17fa::asset::USDC

2. Deploy the Hello Blockchain MOVE contract and interact with it.

So this is taken from Aptos quick start example Your First Move Module. Follow their steps.

STEP 1. download Aptos cli

STEP 2. Compile and Publish hello_blockchain.move to devnet. Take a look at the smart contract, it’s a simple contract with only two methods: get_message and set_message

After contract deployed, you can search aptos explorer with your Wallet address. There’re no separate url for test/devnet, just select from Top Right.

Deployed contracts are under “Modules”, which is tied to your “Account” (i.e. your wallet address)! Unlike EVM compatible chains, there’s no separate contract addresses for individual “Modules”.

Now, please also step into client.py account_resource on debugger:

Look also client.py transaction_pending. It’s obvious if you have a transaction hash, you can just get the transaction details with a simple REST call.

APTOS python SDK is just a HTTP based wrapper.

Wait there’s one more thing I want to show you, look at client.py create_single_signer_bcs_transaction:

They hard coded gas to 100_000 (1_000_000_000 is 1 APT). I reported this in Aptos community. It was however flagged as Spam, lol

Lastly, I searched aptos python SDK in particular client.py . I cannot find a way to query transactions done under a given wallet/account (Have I missed something?). But there’s one here from aptoslabs fullnode!

https://fullnode.mainnet.aptoslabs.com/v1/spec#/operations/get_account_transactions

I guess they are still trying to organise things?! Here’s small code snippet to query and parse aptos transactions.

Depending on “payload_function”, you can add contract-specific parsing logic.

STEP 3. This was taken from Your First Move Module. I just added a little comment. What’s worth noting is, “HelloBlockchainClient” extends aptos_sdk “RestClient” and implementation contains wrapper around smart contract functions “get_message” and “set_message”.

One observation: it takes about 2–3 seconds for each “set_message”. It’s less than amazing I suppose.

After, you should also be able to find alice’s transaction under “Transaction” tab.

Click into it to see the details and what smart contract function it called.

Also take a look inside the SDK (Step into with debugger), for example, account_resource in client.py, this is actually a HTTP request/response wrapper.

From transaction_pending, you’d also be able to see how to fetch transaction details/status:

Ready for more action?

Bridge money in/out of Aptos (My fav https://app.multichain.org/#/router don’t support aptos yet at time of writing)

Swap and yield farming platforms on aptos

Houstonswap https://app.houstonswap.io/swap

(The team who brought to you Singlefinance.io on cronos, also launched Houstonswap)

Liquidswap https://liquidswap.com

If you are a web3 dev coming from EVM compatible chains, take look at liquidswap router contract. You’d notice similar smart contract functions. Take VVS router contract as example, you’d see “getAmountsIn”, “swapTokensForExactTokens”. Compared against Liquidswap router contract, we have “get_amount_in”, “swap_coin_for_exact_coin”. Also from their doc, Liquidswap’s AMM still uses constant product, where as, Houstonswap already moved to on to Concentrated Liquidity Model (As pioneered by Uniswap V3). See the similarities? And differences?

References:

MOVE language reference: https://diem.github.io/move/introduction.html

hello_blockchain.move has two functions: get_message and set_message
https://github.com/aptos-labs/aptos-core/blob/main/aptos-move/move-examples/hello_blockchain/sources/hello_blockchain.move

hello-blockchain.py:
https://github.com/aptos-labs/aptos-core/blob/main/ecosystem/python/sdk/examples/hello-blockchain.py

Liquidswap router contract: https://github.com/pontem-network/liquidswap/blob/main/sources/swap/router.move

--

--

Norman Fung
Norman Fung

No responses yet