On this page we’ll run through some introductory code on getting set up with using Etherspot Prime on Flare.

Installing packages

Prerequisite You should have installed Node.js (version 18.10.0 or higher).

Install Etherspot Prime SDK with this command

A look into the code

Importing the SDK

  import { PrimeSdk } from '@etherspot/prime-sdk';

Getting the smart account address

If you’re unsure about the difference between key based accounts and smart contract accounts, please take a look at this page

In this example we simply create a key based wallet with ethers.js like so:

const randomWallet = ethers.Wallet.createRandom();
setEoaPrivateKey(randomWallet.privateKey);

Then we use this key based wallet to instantiate the SDK on Coston2 and get the wallet address.

const primeSdk = new PrimeSdk({ privateKey: privateKey}, { chainId: 114, bundlerProvider: new EtherspotBundler(114, bundlerApiKey) });
const address: string = await primeSdk.getCounterFactualAddress();
console.log(address);

Sending funds to another address

Now that we have a smart contract account on Coston2, we can fund it using Flare’s offical faucet.

Once we have funds on our account (you can check this here) we can try a simple send operation. This can be done through creating a sendFunds function like so:

We’ll want to save destinationAddress and amount in some input field within the dapp.

const sendFunds = async () => {

    const primeSdk = new PrimeSdk({ privateKey: eoaPrivateKey}, { chainId: 114, bundlerProvider: new EtherspotBundler(114, bundlerApiKey) });
    // clear the transaction batch
    await  primeSdk.clearUserOpsFromBatch();

    // add transactions to the batch
    const transactionBatch = await primeSdk.addUserOpsToBatch({to: destinationAddress, value: ethers.utils.parseEther(destinationAddress)});

    // estimate transactions added to the batch and get the fee data for the UserOp
    const op = await primeSdk.estimate();

    // sign the UserOp and send to bundler
    const uoHash = await primeSdk.send(op);
    console.log(`UserOpHash: ${uoHash}`);
}

Next steps

For next steps you can look at functions or examples to tailor the dapp to what you’re trying to achieve.