All Aptos notes today.
- Accounts and Transactions.
- https://aptos.dev/tutorials/your-first-transaction/.
- Wrote a typescript client that hit testnet (rest api) to perform various actions/transactions on accounts.
- Remember, an account is a resource that can send transactions. Accounts have two things: code (Move modules) and data (Move resources).
- An account holds its own public/private keypair. It also has an authentication key, which allows it to rotate the public/private keypair while still maintaining identity.
- Nacl is a crypto lib for js.
- Aptos REST API: https://fullnode.devnet.aptoslabs.com/spec.html#/.
- Get info from the ledger, get or submit transactions, get account info and modules and resources, get events.
- Instantiate account locally (just a private/public keypair). Then hit the faucet (/mint endpoint) so testnet “creates” your account on the actual blockchain. Then you can call anything on the rest client with your account.
- Transaction. First generate a json with the request parameters (address, seqnum, gas limits, payload, etc). Payload is which function to call and with what arguments (eg 0x1::TestCoin::Transfer). Then sign it with the nacl library (tweetnacl) and add the “signature” field to the same json. Then submit (just a POST of that final json). Then observe state of transaction and block or continue or error handle or whatever.
- To get balance, hit /accountResources then just loop over until you find the 0x1::TestCoin resource.
- You can see the data directly, eg for one of my test accounts: https://fullnode.devnet.aptoslabs.com/accounts/2c0df74faebd29729a0bd9a26de988d7354cc9c1888d363dd324f8fed6a8a02f/resources
- You can also use the aptos explorer: https://aptos-explorer.netlify.app/account/2c0df74faebd29729a0bd9a26de988d7354cc9c1888d363dd324f8fed6a8a02f
- Generic explorer link: https://aptos-explorer.netlify.app/.
- Remember this is all devnet, and very open. A full node could modify your payload before you sign it. The explorer shows auth keys (same as private key, but abstracted so you can rotate the privkey).
- Modules to blockchain.
- https://aptos.dev/tutorials/your-first-move-module/.
- Remember “source ~/.cargo/env” after the aptos clone and dev setup script. From the aptos-core repo, git checkout origin/devnet.
- The Move module specifies a “MessageHolder” resource. It’s a struct with a message, just a string. Then you can query the message, create it, modify it.
- This writes the module, tests it, and publishes it.
- Back to the client; now we can interact with this module. Reference it by its address, and simply change the “payload” of the rest call. Examples for most common payloads are here: https://aptos.dev/transactions/interacting-with-the-aptos-blockchain/
- Contract address for a module is the address that published it. The owner is the person who deployed it. You have to copy this address over to the client, as well as the build output (just like Solana’s IDL and Ethereum’s ABI).
- Full instructions, for later reference: https://aptos.dev/tutorials/your-first-move-module/#step-3-initialize-and-interact-with-the-move-module.
- Minting max on devnet used to be much higher. It appears to be capped at 20,000 TestCoin now.
- You can see it here: Alice’s account has a message AND is the owner of the module so it shows (https://explorer.devnet.aptos.dev/account/28bf53b0d664895b226798584c2d177faf6d40b42bfba4c1af60911436bcff77) while Bob’s account just has a message (https://explorer.devnet.aptos.dev/account/b9b0873fda8187450bbaa9af14c84c814f52720e3dadf7cd6a52fe58dd0988fb).
- NFTs.
- https://aptos.dev/tutorials/your-first-nft/.
- And https://github.com/aptos-labs/aptos-core/blob/main/developer-docs-site/static/examples/typescript/first_nft.ts.
- The spec isn’t developed yet. Aptos NFTs are very much WIP.
- There are generic scripts owned by 0x1 that you may interact with to create collections and such. Can call them via the rest api with the appropriate payload, just like a transaction or just like a module publish.
- You have to know the ID of the NFT. If you know it directly, great. Else, start from the address of its creator and iterate over the resources until you match the token name.
- Then you must make space for the token on accounts that will hold it. This is like creating a token account in solana. It’s called “offer”ing the token in aptos. Then you can claim the token on accounts that have registered it.
- Again, all of these are wrappers around the rest api. Just define the params for that specific script, then call it.
- Kinda nice, compared to candy machine or eth NFTs. You just pass the URL as a param to the rest call and it constructs the json and everything for you. You have a functional interface instead of a config, which makes the clientside implementation pretty easy.
- Transferred an NFT from alice (https://fullnode.devnet.aptoslabs.com/accounts/0d7bd64e9c18d821b57eef5a395ce91e164dd1b6c66fc05d5b8ea0aa4d7900fe/resources) to bob (https://fullnode.devnet.aptoslabs.com/accounts/8528941e2f1102e2c93cefeb872bda3f58c0f0ae33c281f83e400fb2a994a3df/resources).
- Local testnet validator.
- https://aptos.dev/tutorials/run-a-local-testnet/.
- No hardhat or anchor to make this dead simple yet, but it’s in the works.
- 2 ways: build from aptos source (allowing you to modify it) or using prepackaged docker containers (easier, and persists). If you’re going to change the aptos blockchain, do the former; else skip the build and just use the latter.
- From source:
- To start the node: CARGO_NET_GIT_FETCH_WITH_CLI=true cargo run -p aptos-node — –test
- It writes a config file, so you can pick back up there (instead of genesis). It hosts the rest service obviously. Port 8080.
- To start a faucet: cargo run –package aptos-faucet — –chain-id TESTING –mint-key-file-path “<root key path from node start command output>” –address 0.0.0.0 –port 8000 –server-url http://127.0.0.1:8080
- Then you can interact with the faucet and node, just replace the URLs in the first_transaction example with your new localhost addresses.
- From docker:
- Download their two yamls then docker-compose up. You’ll have a node on 8080 and a faucet on 8000, just like the build from source.
- Local devnet fullnode.
- https://aptos.dev/tutorials/run-a-fullnode.
- Work from aptos-core source, as expected. Or docker. Download the genesis file (https://devnet.aptoslabs.com/genesis.blob) and waypoint file (https://devnet.aptoslabs.com/waypoint.txt) and yaml configs. Then run with cargo or docker-compose.
- NoAvailablePeers when first starting. This is because devnet sets max connections per node, and all peers may be full during times of high volume. To bypass this, just define upstream seeds (peers) by their address directly in the config yaml (not the docker-compose yaml).
- Grep the metrics endpoint to check the sync state, compare the number to that on https://status.devnet.aptos.dev/. Took about 10 minutes to sync devnet’s full blockchain (a little more than version 1M) onto my local data drive. Execed into container to check the size of /opt/aptos/data, it’s 7.8GB at this point in time.
- To give your fullnode a static identity, you can use “aptos-operational-tool”. It’s available to build from source in aptos-core and run with cargo, or available in a docker image.
- docker run -i aptoslab/tools:devnet sh -x (drops you into the container, then run the rest)
- aptos-operational-tool generate-key –encoding hex –key-type x25519 –key-file ~/private-key.txt
- aptos-operational-tool extract-peer-from-file –encoding hex –key-file ~/private-key.txt –output-file ~/peer-info.yaml
- Then set the identity in your config and restart the node.
- You can generate a new identity (public/private key) at anytime and restart your node.
- You’ll need to update your node every week when devnet updates.
- You need to statically expose your node too, if you want external connections. Same as bitcoin node. My router’s public ipv4 is 96.239.66.140, my desktop has a static ipv4 lease, and I set up port forwarding rules in the fios router for API and metrics ports etc. Then it hits my host, wsl forwards to the linux VM, then docker forwards to the fullnode running in a container. Ports needs to be exposed through the whole path (docker-compose.yaml and windows firewall). Then restart desktop.
- There’s this site too with some good scripts and helpers: https://ohsnail.com/aptos-fullnode-docker-guide-eng/#-linux-setup
- Aptos nodetester: https://node.aptos.zvalid.com/
- Final node is up: http://96.239.66.140:8080/ and http://96.239.66.140:9101/metrics
- Full API http://96.239.66.140:8080/spec.html.
- Compare block count (version) to official status page: https://status.devnet.aptos.dev/.
- When testnet goes live (incentivized, and prep for mainnet) on May 13th, I assume they’ll provide a new image/genesis/waypoint, as well as upstream seeds of their nodes to kickstart the test network.
- Went through and did an upgrade too.
- docker-compose down –volumes and then docker volume rm <dir>_db -f (just check with docker volume ls)
- Then just update the genesis and waypoint and restart the node.