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.
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.
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.
| npm | yarn |
|---|---|
Begin with npm by following the npm documentation. | For yarn, refer to yarn's installation guide. |
To kickstart your project, open your terminal and execute the following commands:
mkdir aptos-api-quickstart
cd aptos-api-quickstart
npm init --yesThis creates a new directory named aptos-api-quickstart and initializes a Node.js project within it.
Install Axios, a popular HTTP client, to make API requests:
npm install axios
# Or with yarn
# yarn add axiosCreate an index.js file in your project directory and paste the following code:
const axios = require('axios');
const url = `https://aptos-mainnet.g.alchemy.com/v2/${yourAPIKey}/v1/accounts`;
axios.get(url)
.then(response => {
console.log('Accounts:', response.data);
})
.catch(error => {
console.error('Error fetching accounts:', error.message);
});
Remember to replace yourAPIKey with your actual Alchemy API key that you can get from your Alchemy dashboard.
To execute your script and make a request to the Aptos App, run:
node index.jsYou 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": [...]
}
]Well done! You've just made your first request to the Aptos App API.