How to Transition from Old Etherspot SDK to Etherspot Prime

Jul 23, 2023 | Blockchain

The Etherspot SDK has evolved, and with it, so has the way we approach account abstraction on Ethereum. Given that the old version is deprecated, this blog will guide you through the transition to the new Etherspot Prime and help you set up your blockchain development effectively.

Why Move to Etherspot Prime?

The old version of Etherspot SDK adheres to pre-ERC4337 standards, which are now obsolete. The new Etherspot Prime is built around the ERC4337 standard, which offers a much more flexible and powerful framework for developing Ethereum applications. With Etherspot Prime, you can enjoy:

  • Seamless experience across EVM-compatible chains
  • Enhanced features with Buidler and TransactionKit tools
  • A modern architecture designed for current and future needs

Installation Steps

To migrate to Etherspot Prime, you’ll need to install the updated packages. Here’s how to do it:

bash
$ npm i ethers@^5.5.2 reflect-metadata@^0.1.13 rxjs@^6.6.2 -S
$ npm i etherspot -S
$ npm i ws -s # node.js only

Using the Etherspot SDK

Upon successful installation, you can start utilizing the features of the Etherspot SDK. Let’s make an analogy to unravel this process: Imagine you’re an architect (a developer) who has just received the blueprints for a new, innovative building (the Etherspot Prime SDK). You’ll need specific tools (the SDK packages) to construct this building.

Below is a simplified implementation showing how to create and manage a contract account:

typescript
import Sdk, { randomPrivateKey } from 'etherspot';

const PRIVATE_KEY = randomPrivateKey();

async function main() {
    const sdk = new Sdk(PRIVATE_KEY);
    sdk.notifications$.subscribe(notification => console.log('notification:', notification));
    
    await sdk.computeContractAccount();
    const account = sdk.state;
    
    console.log('contract account:', account);
    
    // Top-up contract account (account.address)
    // Add transaction to gateway batch
    await sdk.batchExecuteAccountTransaction({
        to: '0xEEb4801FBc9781EEF20801853C1Cb25faB8A7a3b',
        value: 100,  // 100 wei
    });
    
    console.log('gateway batch estimation:', await sdk.estimateGatewayBatch());
    console.log('submitted gateway batch:', await sdk.submitGatewayBatch());
}

main().catch(console.error);

Understanding the Code

In the code above:

  • The architect starts with a foundation (creating an instance of the SDK using a random private key).
  • Next, notifications act like safety inspections, ensuring that any changes are logged.
  • As we compute the contract account, it’s akin to framing up the structure, preparing for transactions to flow through.
  • The code then handles funding—like adding resources to a construction project—ensuring everything runs smoothly.
  • Lastly, estimating and submitting the gateway batch is like scheduling final checks before moving into the finished building.

Troubleshooting Common Issues

If you encounter issues while setting up or using Etherspot Prime, here are some troubleshooting ideas:

  • Ensure that you have the correct versions of the dependencies installed. Mismatched versions can cause complications.
  • If notifications are not appearing as expected, confirm that your environment supports them.
  • For incomplete transaction histories on the Klaytn network, be aware that certain limitations exist due to resource availability.
  • If you face connectivity issues, check your internet stability and the websocket availability for node.js applications.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

Resources for Further Learning

To deepen your understanding and skills with Etherspot, be sure to check out the following resources:

Final Thoughts

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox