This how-to guide will give you an overview of Aptos and help you get started building with Validation Cloud’s Node API.
Aptos addresses the critical demands of decentralized applications with an emphasis on scalability, safety, reliability, and upgradeability. Created from a collaborative effort involving over 350 developers worldwide, Aptos incorporates state-of-the-art innovations in its foundation. The platform is powered by an optimistic concurrency control engine known as Block-STM, as well as a BFT Proof-of-Stake mechanism known as Jolteon. The introduction of the Move programming language is a defining characteristic, offering a secure and adaptable environment for application development. The recent native integration of Aptos Keyless Accounts is a revolutionary enabling familiar Web2 logins to support transacting on the Aptos blockchain. This novel architecture, emphasizing rigorous and rapid enhancement, positions Aptos as a clear leader in making Web3 technologies accessible on a global scale.
For developers eager to explore the benefits of the Aptos blockchain, Validation Cloud's Aptos API offers a powerful and seamless entry point.
To get started, our comprehensive documentation provides a clear roadmap for setting up your development environment and connecting to the Aptos Network. In the next section, we’ll walk you through setup, querying the chain, importing your key to an Aptos account, simulating a transaction, and then sending a transaction. First, sign up for free at validationcloud.io, and create your Aptos API key.
Create a ‘.env’ file in your project root to store your API key from app.validationcloud.io.
Let’s start by connecting to Aptos and fetching some ledger info. The returned values will include the chainID, epoch, ledger version, timestamp, the git hash, and the blockheight, among a couple other properties.
For this method call, we’ll build off of the information from #1 to grab the latest block, and then run another call to get that latest block’s details.
Retrieving an account by its address on the Aptos blockchain, even if it only provides basic information such as the authentication key and sequence number, serves several practical purposes. The authentication key is crucial for confirming the identity and the cryptographic credentials associated with the account, which is fundamental for security and transaction verification processes. This key helps ensure that any transaction submitted is genuinely from the account holder. The sequence number of an account, on the other hand, is vital for transaction ordering. Each transaction from an account must have a sequence number greater than the last confirmed transaction.
An example of an account resource on Aptos could be the coin balance resource.
For instance, the 0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin> resource defines the balance of Aptos Coins (the native currency) held in an account, including methods for managing these funds like depositing and withdrawing. Fetching an account resource on the Aptos blockchain provides valuable insights into the state of a specific account. This operation is crucial for developers and users wanting to understand the properties and current state of an account, such as its balances, sequence numbers, and associated modules and resources.
Note, getting the coin resource defaults to the unit of “microAptos,” so we convert it to APT for readability below.
If you’ve ever made a mistake issuing a transaction on Web3 before and wished you could have known the mistake in advance, you’re not alone!
Simulating a transaction on Aptos is a powerful tool for developers and users to predict and analyze the outcome of a transaction without committing it to the blockchain. This simulation reveals whether a transaction will succeed or fail, and provides details about the changes it would make if committed, such as gas costs and state mutations. This is invaluable for debugging and optimizing smart contracts and transactions before they go live, which can save time and reduce costs by preventing failed transactions and their associated fees. Moreover, simulation helps in stress-testing smart contracts under various conditions to ensure their robustness and security, enhancing trust in the applications built on top of the Aptos platform.
We will now be using the Aptos official TS SDK (which contains utilities for transaction signing and broadcasting) to simulate sending 0.01 APT from one account to another.
Note: Before issuing tokens to any Aptos account via the SDK, the account must have registered to receive tokens first. Creating a CoinStore resource on an account for storing coins will resolve any errors encountered here, alternatively, a wallet extension can be used to send APT tokens to the account in question, creating the coin resource on the account automatically.
Note 2: The private key exported for these examples was from the Martian wallet. As of writing, the key format exported was legacy, and Ed25519 format.
Keeping everything above the function in the prior example the same, the following code essentially alters the transaction.simulate to a transaction.submit, now calling the appropriate client resources to commit the transaction to the blockchain itself.
Through these examples, you've learned how to effectively interact with the Aptos blockchain using TypeScript and Axios. This tutorial should serve as a foundation for building more complex applications on top of the Aptos platform. Stay tuned for future posts where we'll dive deeper into smart contract interactions and node API possibilities.