Create Accounts

Step 1: Initiate the clients

In the first step, the transfer_coin example initializes the Aptos client:


const APTOS_NETWORK: Network =
NetworkToNetworkName[process.env.APTOS_NETWORK] || Network.DEVNET;
const config = new AptosConfig({ network: APTOS_NETWORK });
const aptos = new Aptos(config);

By default, the Aptos client points to Aptos devnet services. However, it can be configured with the network input argument


Step 2: Creating local accounts

The next step is to create two accounts locally. Accounts represent both on and off-chain state. Off-chain state consists of an address and the public/private key pair used to authenticate ownership. This step demonstrates how to generate that off-chain state.


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


Step 3: Creating blockchain accounts

In Aptos, each account must have an on-chain representation in order to receive tokens and coins and interact with other dapps. An account represents a medium for storing assets; hence, it must be explicitly created. This example leverages the Faucet to create and fund Alice's account and to create but not fund Bob's account:


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