Setup Accounts

Initialize Aptos TypeScript SDK client

First, let's initialize the Aptos client, we'll choose Devnet as our network, unless the APTOS_NETWORK environment variable is set.


import { Account, Network, NetworkToNetworkName, AptosConfig, Aptos } from "@aptos-labs/ts-sdk"
const APTOS_NETWORK: Network = NetworkToNetworkName[process.env.APTOS_NETWORK] || Network.DEVNET;
const config = new AptosConfig({ network: APTOS_NETWORK });
const aptos = new Aptos(config);


Generate Accounts

Next, we generate two accounts, Alice and Bob, that we'll use for creating and transferring NFTs. Note that, Account.generate() only creates the keys for the accounts, but does not create the on-chain state.


const alice = Account.generate();
const bob = Account.generate();


Create and Fund accounts

In order to initialize the Account on-chain. It must be explicitly created. On test networks such as devnet or testnet you can request the account be created and funded with a Faucet for testing purposes. This example uses the default faucets to fund and create accounts for Alice and Bob. Each account is funded with 10_000_000 Octas or one full AptosCoin.


await aptos.fundAccount({
accountAddress: alice.accountAddress,
amount: 100_000_000,
});
await aptos.fundAccount({
accountAddress: bob.accountAddress,
amount: 100_000_000,
});