Installation setup
Prerequisites
Before using the API, ensure you have the following installed:
Node.js (version 18 or higher)
npm (for package management)
Installation
Install required dependencies with these commands:
npm install dotenv axios @aptos-labs/ts-sdk
Aptos Client & Account Setup
Configure your TypeScript environment with this template:
// Import required packages
import dotenv from 'dotenv';
import axios from 'axios';
import {
AptosConfig,
Aptos,
Network,
Account,
Ed25519PrivateKey,
PrivateKeyVariants
} from "@aptos-labs/ts-sdk";
// Load environment variables
dotenv.config();
// Initialize Aptos client
const config = new AptosConfig({ network: Network.TESTNET });
const aptos = new Aptos(config);
// Configure account
const formattedPrivateKey = PrivateKey.formatPrivateKey(
process.env.APTOS_PRIVATEKEY || '',
'ed25519' as PrivateKeyVariants
);
const account = Account.fromPrivateKey({
privateKey: new Ed25519PrivateKey(formattedPrivateKey),
});
Last updated