Package Exports
- @layerzerolabs/lz-corekit-aptos
- @layerzerolabs/lz-corekit-aptos/package.json
Readme
@layerzerolabs/lz-corekit-aptos
The Aptos CoreKit is a comprehensive SDK designed to interact with the Aptos blockchain. It provides a set of utilities and modules to facilitate the development and integration of applications with the Aptos blockchain.
Features
- Retrieve Account Information: Gets the balance of the specified address.
- Retrieve Block Information: Gets the block height, timestamp and related transactions of the specified block.
- Transaction Management: Get, build, sign, send and confirm transactions.
Installation
To install the Aptos CoreKit, you can use npm or yarn:
npm install @layerzerolabs/lz-corekit-aptos
or
yarn add @layerzerolabs/lz-corekit-aptos
Usage
Initialization
import { AptosProvider } from "@layerzerolabs/lz-corekit-aptos";
// url is the Aptos chain full node url
const url = "http://127.0.0.1:8080/v1";
const provider = AptosProvider.from(url);
If you need to fund your accounts and scan module events by Aptos Indexer, you may need to specify the url of faucet and indexer.
import { AptosProvider } from "@layerzerolabs/lz-corekit-aptos";
// url is the Aptos chain full node url
const url = "http://127.0.0.1:8080/v1";
const faucetUrl = "http://127.0.0.1:8081";
const indexerUrl = "http://127.0.0.1:8090/v1/graphql";
const provider = AptosProvider.from(url, faucetUrl, indexerUrl);
Retrieve Account Information
Get Account Balance
import { AptosProvider } from "@layerzerolabs/lz-corekit-aptos";
// url is the Aptos chain full node url
const url = "http://127.0.0.1:8080/v1";
const provider = AptosProvider.from(url);
const address = "0x1";
const balance = await provider.getBalance(address);
Retrieve Block Information
Get Latest Block Height
import { AptosProvider } from "@layerzerolabs/lz-corekit-aptos";
// url is the Aptos chain full node url
const url = "http://127.0.0.1:8080/v1";
const provider = AptosProvider.from(url);
const number = await provider.getBlockNumber();
Transaction Management
Get Transaction by hash
import { AptosProvider } from "@layerzerolabs/lz-corekit-aptos";
// url is the Aptos chain full node url
const url = "http://127.0.0.1:8080/v1";
const provider = AptosProvider.from(url);
const hash = "0x1";
const tx = await provider.getTransaction(hash);
Sign, Send and Confirm Transaction
import { AptosProvider, AptosSigner } from '@layerzerolabs/lz-corekit-aptos'
import { SignedTransaction, TransactionReceipt, TransactionRequest } from '@layerzerolabs/lz-core'
// url is the Aptos chain full node url
const url = 'http://127.0.0.1:8080/v1'
const provider = AptosProvider.from(url)
const privateKey = '0x1234'
const signer = AptosSigner.from(privateKey)
signer.connect(provider)
const tx: TransactionRequest = ...
const stx: SignedTransaction = await signer.signTransaction(tx)
const receipt: TransactionReceipt = await signer.sendAndConfirm(stx)