Module方法调用
account.ts
// account.ts
import { AptosAccount, HexString } from "aptos";
const privKey = new HexString("Your private key").toUint8Array();
export const aptosAccount = new AptosAccount(privKey);
chain.ts
// chain.ts
import { AptosClient, FaucetClient, MaybeHexString, TokenClient } from "aptos";
const APTOS_NODE_URL_MAIN = 'https://fullnode.mainnet.aptoslabs.com'
const APTOS_NODE_URL_DEV = 'https://fullnode.devnet.aptoslabs.com'
const APTOS_FAUCET_URL_DEV = 'https://faucet.devnet.aptoslabs.com'
export const isMainnet = false;
// Initialize aptos client
// This client is used to interact with aptos blockchain
const aptosNodeUrl = isMainnet ? APTOS_NODE_URL_MAIN : APTOS_NODE_URL_DEV;
export const aptosClient = new AptosClient(aptosNodeUrl);
export const tokenClient = new TokenClient(aptosClient);
// For dev purpose, we need to fund our account with faucet.
export const fundAccountForDev = (address: MaybeHexString) => {
const faucetClient = new FaucetClient(APTOS_NODE_URL_DEV, APTOS_FAUCET_URL_DEV);
faucetClient.fundAccount(address, 100_000_000);
}
Last updated