Aptos API Quickstart

💡 Available only with Blast access

Introduction

Aptos is a next-generation Layer 1 blockchain designed for scalability, safety, and upgradeability. It leverages the Move programming language and a novel consensus mechanism to achieve high throughput and low latency.

With its modular architecture, Aptos supports frequent and instant upgrades, making it a dynamic platform for developers and users alike.


What is the Aptos Chain API?

The Aptos API provides developers with a set of tools to interact with the Aptos blockchain.

It offers both RESTful and JSON-RPC endpoints, allowing for seamless integration, transaction management, wallet interactions, and more.

Key features include:

  • Account and Wallet Management: Create and manage Aptos accounts, check balances, and send/receive tokens.
  • Transaction Handling: Initiate, sign, and broadcast transactions.
  • Blockchain Data: Query blockchain data, such as account balances, block information, and transaction details.
  • Smart Contract Execution: Interact with Aptos smart contracts to perform decentralized actions.
  • Gas Estimates: Get current gas fees and estimate transaction costs.
  • Event Streams: Subscribe to real-time blockchain events through WebSockets.
  • Resource Access: Access blockchain resources like token metadata, account states, and more.

Getting Started Instructions

1. Choose a Package Manager (npm or yarn)

Your first step involves selecting a package manager, which will be crucial for managing your project’s dependencies. The choice between npm and yarn depends on your personal preference or project requirements.

npmyarn
Begin with npm by following the npm documentation.For yarn, refer to yarn’s installation guide.

2. Set Up Your Project

To kickstart your project, open your terminal and execute the following commands:

mkdir aptos-api-quickstart
cd aptos-api-quickstart
npm init --yes

This creates a new directory named aptos-api-quickstart and initializes a Node.js project within it.

3. Make Your First Request

Install Axios, a popular HTTP client, to make API requests:

bash
$npm install axios
># Or with yarn
># yarn add axios

Create an index.js file in your project directory and paste the following code:

javascript
1const axios = require('axios');
2
3const url = `https://aptos-mainnet.alchemy-blast.com/v2/${yourAPIKey}/v1/accounts`;
4
5axios.get(url)
6.then(response => {
7 console.log('Accounts:', response.data);
8})
9.catch(error => {
10 console.error('Error fetching accounts:', error.message);
11});

Remember to replace yourAPIKey with your actual Alchemy API key that you can get from your Alchemy dashboard.

4. Run Your Script

To execute your script and make a request to the Aptos App, run:

bash
$node index.js

You should see a list of Aptos accounts (if any exist on your node or fullnode) outputted to your console. For example:

[
{
"authentication_key": "0x...",
"sequence_number": "0",
"modules": [...],
"resources": [...]
}
]

Next Steps

Well done! You’ve just made your first request to the Aptos App API. With this foundation, you can dive deeper into the array of JSON-RPC methods available on Aptos App and start building your dApps on it!