You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We provide several Enhanced APIs, which are especially useful for querying information about the smart accounts you create using Account Kit, such as the account's owned NFTs using the NFT API.
For the purposes of our example, we will use the NFT API to query our smart account's data by extending the Alchemy Smart Account Client with Enhanced APIs.
Install the alchemy-sdk
We have developed a Typescript SDK to make development with the Enhanced APIs simple. The SDK includes ways to leverage Alchemy's Simulation API, Token API, Transact API, NFT API, Webhooks and Websockets, and more across our supported chains. Take a look at the code here.
We will use the Alchemy SDK Client to extend our Alchemy Smart Account Client using the client's alchemyEnhancedApiActions method. That way, our client will have direct access to the Enhanced APIs.
To use the Alchemy SDK in our project directory, we will need to install the required package:
npm i alchemy-sdk
Extend the Alchemy Smart Account Client with Enhanced APIs
Then, all we need to do is create an alchemy client from the Alchemy SDK, create an AlchemySmartAccountClient from Account Kit, and then extend the client with functionality from the SDK client using alchemyEnhancedApiActions. We can get the smart account's address from the AlchemySmartAccountClient in order to fetch the smart account's NFT in just 1 line of code!
import{alchemyEnhancedApiActions,createModularAccountAlchemyClient,}from"@alchemy/aa-alchemy";import{LocalAccountSigner,sepolia}from"@alchemy/aa-core";import{Alchemy,Network}from"alchemy-sdk";constalchemy=newAlchemy({network: Network.ETH_SEPOLIA,apiKey: "YOUR_API_KEY",});constclient=(awaitcreateModularAccountAlchemyClient({chain: sepolia,apiKey: "YOUR_API_KEY",signer: LocalAccountSigner.mnemonicToAccountSigner("OWNER_MNEMONIC"),})).extend(alchemyEnhancedApiActions(alchemy));constaddress=client.getAddress();// get all NFTs owned by the smart accountexportconstnfts=client.nft.getNftsForOwner(address);
Note that we must configure the Alchemy SDK client to have the same API Key and blockchain network as Alchemy Smart Account Client it is extending via alchemyEnhancedApiActions. This method explicitly checks this requirement and will throw an error at runtime if not satisfied.
Additionally, since the Alchemy SDK client does not yet support JWT authentication, an AlchemySmartAccountClient initialized with JWTs cannot use this method. We must be initialize the client with an API key or RPC URL.
That's it! There are so many more Enhanced APIs the Alchemy SDK exposes, and can be useful for development with Account Abstraction. Try it out here, and check out How to fetch a Smart Account's ERC-20 Tokens for another example.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
We provide several Enhanced APIs, which are especially useful for querying information about the smart accounts you create using Account Kit, such as the account's owned NFTs using the NFT API.
For the purposes of our example, we will use the NFT API to query our smart account's data by extending the Alchemy Smart Account Client with Enhanced APIs.
We have developed a Typescript SDK to make development with the Enhanced APIs simple. The SDK includes ways to leverage Alchemy's Simulation API, Token API, Transact API, NFT API, Webhooks and Websockets, and more across our supported chains. Take a look at the code here.
We will use the Alchemy SDK Client to extend our Alchemy Smart Account Client using the client's alchemyEnhancedApiActions method. That way, our client will have direct access to the Enhanced APIs.
To use the Alchemy SDK in our project directory, we will need to install the required package:
Then, all we need to do is create an alchemy client from the Alchemy SDK, create an AlchemySmartAccountClient from Account Kit, and then extend the client with functionality from the SDK client using alchemyEnhancedApiActions. We can get the smart account's address from the AlchemySmartAccountClient in order to fetch the smart account's NFT in just 1 line of code!
Note that we must configure the Alchemy SDK client to have the same API Key and blockchain network as Alchemy Smart Account Client it is extending via alchemyEnhancedApiActions. This method explicitly checks this requirement and will throw an error at runtime if not satisfied.
Additionally, since the Alchemy SDK client does not yet support JWT authentication, an AlchemySmartAccountClient initialized with JWTs cannot use this method. We must be initialize the client with an API key or RPC URL.
That's it! There are so many more Enhanced APIs the Alchemy SDK exposes, and can be useful for development with Account Abstraction. Try it out here, and check out How to fetch a Smart Account's ERC-20 Tokens for another example.
Beta Was this translation helpful? Give feedback.
All reactions