Installation
Magic interacts with the Aptos blockchain via Magic’s extension NPM 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 and/or @aptos-labs/wallet-adapter-core.
NOTEThis extension requires @magic-ext/aptos version ^0.5.0 , and magic-sdk version ^17.1.6 (latest preferred)
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. You can use any supported login method supported by Magic SDK in the “connect” function.JavaScript
WARNINGThe nodeUrl you specify will determine whether you are using the mainnet or testnet for Aptos.
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 to get started. You can check if a user is logged in with the following code:JavaScript
JavaScript
Note: this does not return an actual AptosAccount object, only the address. See the note below for more detail.
account()
method:
JavaScript
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 TutorialJavaScript
Sign and Send Transaction
Note that the Magic Aptos extension follows the method names and conventions of Aptos’ TypeScript SDK. If you are using MagicAptosWallet, you can skip the rest of this section and build your application using the Aptos Wallet Standard. You can also find example apps by Aptos here (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).WARNINGThe Beta version of the Magic Aptos Extension only supports Raw transactions. Future versions will include full support for the following: - CoinClient - TokenClient - AptosAccountIn 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.
JavaScript
Get Balance
JavaScript