Skip to main content

Nil.js: creating a smart account

Nil.js library exposes the SmartAccountV1 class that allows for quickly creating and deploying a new smart account:

import { HttpTransport, PublicClient, generateSmartAccount } from "@nilfoundation/niljs";

const client = new PublicClient({
transport: new HttpTransport({
endpoint: RPC_ENDPOINT,
}),
shardId: 1,
});

const smartAccount = await generateSmartAccount({
shardId: 1,
rpcEndpoint: RPC_ENDPOINT,
faucetEndpoint: FAUCET_ENDPOINT,
});

This example initializes a new smart account, provides it with a Signer and requests a top up to the smart account address. The smart account is then deployed.

Seqno

When using the client library, seqno defaults to 0 for every transaction sent via the smart account. If too many transactions are sent at the same time with this seqno, they will fail. To avoid this issue, set the seqno manually whenever using the smart account:

smartAccount.sendTransaction({
...
seqno: SEQNO,
...
})