> ## Documentation Index
> Fetch the complete documentation index at: https://docs.magic.link/llms.txt
> Use this file to discover all available pages before exploring further.

# Aptos

## Installation

Magic interacts with the [Aptos](https://aptoslabs.com/) blockchain via Magic's extension NPM package [`@magic-ext/aptos`](https://www.npmjs.com/package/@magic-ext/aptos) (beta version 0.5.0). Additionally, the Aptos extension lets you interact with the blockchain using methods from [Aptos' TypeScript SDK](https://aptos.dev/sdks/ts-sdk/index) and/or [@aptos-labs/wallet-adapter-core](https://github.com/aptos-labs/aptos-wallet-adapter).

<Note>
  **NOTE**

  This extension requires @magic-ext/aptos version ^0.5.0 , and magic-sdk version ^17.1.6 (latest preferred)
</Note>

To get started, install the following dependencies for your project:

<CodeGroup>
  ```bash NPM icon="npm" theme={null}
  npm install @aptos-labs/wallet-adapter-core @magic-ext/aptos magic-sdk
  ```

  ```bash Yarn icon="yarn" theme={null}
  yarn add @aptos-labs/wallet-adapter-core @magic-ext/aptos magic-sdk
  ```
</CodeGroup>

## Initialization

The Magic class is the entry-point to the Magic SDK. It must be instantiated with a Magic **publishable** key.

You can then use the SDK object to initialize an AptosWallet object that meets the [Aptos Wallet standard](https://aptos.dev/standards/wallets/). You can use any [supported login method](/embedded-wallets/authentication/overview) supported by Magic SDK in the "connect" function.

```js JavaScript icon="square-js" theme={null}
import { Magic } from 'magic-sdk';
import { AptosExtension } from '@magic-ext/aptos';

const magic = new Magic('YOUR_API_KEY', {
  extensions: [
    new AptosExtension({
      nodeUrl: 'https://fullnode.testnet.aptoslabs.com'
    }),
  ],
});

const magicAptosWallet = new MagicAptosWallet(magic, {
  connect: async () => {
    await magic.auth.loginWithMagicLink({ email });
    const accountInfo = await magic.aptos.getAccountInfo();
    return accountInfo;
  }
});
```

<Warning>
  **WARNING**

  The **nodeUrl** you specify will determine whether you are using the **mainnet** or **testnet** for Aptos.
</Warning>

## Common Methods

### Send Transaction

#### Getting the Aptos Account

The first step will be getting the logged in user's Aptos account address. Follow any of the login guides on the [Authentication tab](/embedded-wallets/authentication/overview) to get started. You can check if a user is logged in with the following code:

```javascript JavaScript icon="square-js" theme={null}
const isLoggedIn = await magic.user.isLoggedIn();
```

Once the user is logged in, you can get their Aptos account address by running:

```javascript JavaScript icon="square-js" theme={null}
const { address } = await magic.aptos.getAccountInfo();
```

<Info>
  Note: this does not return an actual AptosAccount object, only the address. See [the note below](/embedded-wallets/blockchains/non-evm/aptos#sign-and-send-transaction) for more detail.
</Info>

Alternatively, you can use MagicAptosWallet's `account()` method:

```javascript JavaScript icon="square-js" theme={null}
const { address } = await magicAptosAccount.account();
```

#### Funding an Account with the Faucet

Next up for our testing, you'll need to fund the account using the Faucet. This code snippet is taken from the [Aptos Tutorial](https://aptos.dev/tutorials/your-first-transaction#step-43-creating-blockchain-accounts)

```javascript JavaScript icon="square-js" theme={null}
const DEVNET_NODE_URL = 'https://fullnode.testnet.aptoslabs.com';
const DEVNET_FAUCET_URL = 'https://faucet.testnet.aptoslabs.com';
const faucetClient = new FaucetClient(DEVNET_NODE_URL, DEVNET_FAUCET_URL);
⁠await faucetClient.fundAccount(address, 100_000_000);
```

### Sign and Send Transaction

Note that the Magic Aptos extension follows the method names and conventions of [Aptos' TypeScript SDK](https://aptos.dev/sdks/ts-sdk/index).

If you are using MagicAptosWallet, you can skip the rest of this section and build your application using the [Aptos Wallet Standard](https://aptos.dev/standards/wallets/). You can also find example apps by Aptos [here](https://github.com/aptos-labs/aptos-wallet-adapter/tree/main/apps/nextjs-example) (MagicAptosWallet is not included in this useWallet, however, due to the flexibility Magic SDK provides - and the complexity of setting it up does not neatly fit into this example's React hook).

<Warning>
  **WARNING**

  The Beta version of the Magic Aptos Extension only supports Raw transactions. Future versions will include full support for the following: - CoinClient - TokenClient⁠ - AptosAccount

  In the meantime, you can find the equivalent RawTransactions in the Aptos source code for any of the object methods above. See the bottom of this page for a detailed example.
</Warning>

```javascript JavaScript icon="square-js" theme={null}
// Set the input variables
const MAGIC_WALLET_ADDRESS = '0x906fd65afe31b7237cd4d7c4073d8bf76c61b6a24ec64dd26f0c16de5c2444d5'
const SAMPLE_RAW_TRANSACTION = {
  function: "0x1::coin::transfer",
  type_arguments: ["0x1::aptos_coin::AptosCoin"],
  arguments: [MAGIC_WALLET_ADDRESS, 1000]
}

⁠
// Initialize the AptosClient and transaction
const client = new AptosClient(DEVNET_NODE_URL);
const rawTransaction = await client.generateTransaction(address, SAMPLE_RAW_TRANSACTION)

// Sign the transaction using Magic SDK, then send
const signedTransaction = await magic.aptos.signTransaction(rawTransaction)
⁠const transaction = await client.submitTransaction(signedTransaction)
const result = await client.waitForTransactionWithResult(transaction.hash, {
  checkSuccess: true
})
```

### Get Balance

```javascript JavaScript icon="square-js" theme={null}
const address = await magic.aptos.getAccountInfo();
const client = new AptosClient(DEVNET_NODE_URL);
const coinClient = new CoinClient(client);

const balance = await coinClient.checkBalance(address);
console.log(balance)
```

## Resources

* [Aptos Wallet Adapter](https://github.com/magiclabs/aptos-wallet-adapter)
* [Magic Aptos Example](https://github.com/magiclabs/example-aptos)
