Before doing anything with the SDK, we must instantiate it.
This will create the Etherspot smart account based off of the values we pass in.
Step 1. Import the Etherspot Modular SDK.
import { ModularSdk } from '@etherspot/modular-sdk';
Step 2. Instantiate the SDK with below initialisation properties using this block of code.
- privateKey
- ChainID
- bundlerProvider
- bundlerApiKey
- customBundlerUrl (can be left empty)
const modularSdk = new ModularSdk(
{
privateKey: process.env.WALLET_PRIVATE_KEY
},
{
chainId: Number(process.env.CHAIN_ID),
bundlerProvider: new EtherspotBundler(Number(process.env.CHAIN_ID),
bundlerApiKey, customBundlerUrl)
}
);
And that’s it! You’re now ready to call any of the Modular SDK functions.
You can also pass in different parameters when instantiating the SDK.
- chainId : The chain ID of the blockchain.
- customBundlerUrl : The bundler you wish to use.
Sending funds to another address
const recipient = '';
const value = '0.0000001';
const address: string = await modularSdk.getCounterFactualAddress();
console.log('\x1b[33m%s\x1b[0m', `EtherspotWallet address: ${address}`);
await modularSdk.clearUserOpsFromBatch();
const transactionBatch = await modularSdk.addUserOpsToBatch({ to: recipient, value: ethers.utils.parseEther(value) });
console.log('transactions: ', transactionBatch);
const balance = await modularSdk.getNativeBalance();
console.log('balances: ', balance);
const op = await modularSdk.estimate();
console.log(`Estimate UserOp: ${await printOp(op)}`);
const uoHash = await modularSdk.send(op);
console.log(`UserOpHash: ${uoHash}`);
console.log('Waiting for transaction...');
let userOpsReceipt = null;
const timeout = Date.now() + 60000;
while ((userOpsReceipt == null) && (Date.now() < timeout)) {
await sleep(2);
userOpsReceipt = await modularSdk.getUserOpReceipt(uoHash);
}
console.log('\x1b[33m%s\x1b[0m', `Transaction Receipt: `, userOpsReceipt);
}
Next steps
For next steps you can look at functions or examples
to tailor the dapp to what you’re trying to achieve.
In the next page we’ll take a look at the various functions the SDK offers.