Skip to main content

Class: SmartAccountV1

SmartAccountV1 is a class used for performing operations on the cluster that require authentication.

SmartAccountV1

Implements

Constructors

new SmartAccountV1()

new SmartAccountV1(param0): SmartAccountV1

Creates an instance of SmartAccountV1.

Parameters

ParameterTypeDescription

param0

SmartAccountV1Config

The object representing the initial smart account config. See SmartAccountV1Config.

Returns

SmartAccountV1

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:153

Properties

address

address: 0x${string};

The smart account address.

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:139


client

client: PublicClient;

The client for interacting with the smart account.

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:121


pubkey

pubkey: Uint8Array<ArrayBufferLike>;

The smart account public key.

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:109


salt?

optional salt: Uint8Array<ArrayBufferLike>;

Arbitrary data for changing the smart account address.

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:127


shardId

shardId: number;

The ID of the shard where the smart account is deployed.

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:115


signer

signer: ISigner;

The smart account signer.

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:133


abi

static abi: any = SmartAccount.abi;

The smart account ABI.

Static

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:50


code

static code: Uint8Array<ArrayBufferLike>;

The smart account bytecode.

Static

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:43

Methods

burnToken()

burnToken(amount): Promise<Transaction>

Burns the token that the smart account owns.

Parameters

ParameterType

amount

bigint

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Example

const tx = await smartAccount.burnToken(burnToken);
await tx.wait();

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:463


checkDeploymentStatus()

checkDeploymentStatus(): Promise<boolean>

Checks the deployment status.

Returns

Promise<boolean>

The current deployment status.

Async

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:281


deployContract()

deployContract(param0): Promise<object>

Deploys a new smart contract via the smart account.

Parameters

ParameterTypeDescription

param0

DeployParams

The object representing the contract deployment params.

Returns

Promise<object>

The object containing the deployment transaction and the contract address.

address
address: 0x${string};
tx
tx: Transaction;

Async

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:519


getBalance()

getBalance(): Promise<bigint>

Returns the smart account balance.

Returns

Promise<bigint>

The smart account balance.

Async

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:681


mintToken()

mintToken(amount): Promise<Transaction>

Mints the token that the smart account owns and withdraws it to the smart account. setTokenName has to be called first before minting a token.

Parameters

ParameterType

amount

bigint

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Example

const tx = await smartAccount.mintToken(mintCount);
await tx.wait();

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:449


requestToSmartAccount()

requestToSmartAccount(requestParams, send?): Promise<object>

Performs a request to the smart account.

Parameters

ParameterTypeDefault valueDescription

requestParams

RequestParams

undefined

The object representing the request parameters.

send?

boolean

true

The flag that determines whether the request is sent when the function is called.

Returns

Promise<object>

The transaction bytecode and hash.

chainId
chainId: number;
hash
hash: Uint8Array<ArrayBufferLike>;
raw
raw: Uint8Array<ArrayBufferLike>;
seqno
seqno: number;

Async

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:294


selfDeploy()

selfDeploy(waitTillConfirmation?, feeCredit?): Promise<Transaction>

Deploys the smart account.

Parameters

ParameterTypeDefault valueDescription

waitTillConfirmation?

boolean

true

The flag that determines whether the function waits for deployment confirmation before exiting.

feeCredit?

bigint

undefined

The fee credit for processing the deployment transaction. If not set, it will be estimated automatically.

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Example

import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
SmartAccountV1,
generateRandomPrivateKey,
} from '@nilfoundation/niljs';
const client = new PublicClient({
transport: new HttpTransport({
endpoint: RPC_ENDPOINT,
}),
shardId: 1,
});
const signer = new LocalECDSAKeySigner({
privateKey: generateRandomPrivateKey(),
});
const faucet = new Faucet(client);
await faucet.withdrawTo(smartAccountAddress, 100000n);
const pubkey = signer.getPublicKey();
const smartAccount = new SmartAccountV1({
pubkey: pubkey,
salt: 100n,
shardId: 1,
client,
signer,
address: SmartAccountV1.calculateSmartAccountAddress({
pubKey: pubkey,
shardId: 1,
salt: 100n,
}),
});
await smartAccount.selfDeploy(true);

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:212


sendRawInternalTransaction()

sendRawInternalTransaction(rawTransaction): Promise<Transaction>

Send a raw signed transaction via the smart account.

Parameters

ParameterTypeDescription

rawTransaction

Uint8Array<ArrayBufferLike>

The transaction bytecode.

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:494


sendTransaction()

sendTransaction(param0): Promise<Transaction>

Send a transaction via the smart account.

Parameters

ParameterTypeDescription

param0

XOR<SendDataTransactionParams, SendAbiTransactionParams>

The object representing the transaction params.

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Example

const anotherAddress = SmartAccountV1.calculateSmartAccountAddress({
pubKey: pubkey,
shardId: 1,
salt: 200n,
});
await smartAccount.sendTransaction({
to: anotherAddress,
value: 10n,
gas: 100000n,
});

Implementation of

SmartAccountInterface.sendTransaction

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:350


setTokenName()

setTokenName(name): Promise<Transaction>

Sets the name of the custom token that the smart account can own and mint.

Parameters

ParameterType

name

string

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Example

const tx = await smartAccount.setTokenName("MY_TOKEN");
await tx.wait();

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:423


syncSendTransaction()

syncSendTransaction(param0): Promise<Transaction>

Creates a new transaction and performs a synchronous call to the specified address.

Parameters

ParameterTypeDescription

param0

XOR<SendSyncDataTransactionParams, SendSyncAbiTransactionParams>

The object representing the transaction params.

Returns

Promise<Transaction>

A Transaction object that can be awaited for completion.

Async

Example

const anotherAddress = SmartAccountV1.calculateSmartAccountAddress({
pubKey: pubkey,
shardId: 1,
salt: 200n,
});
const tx = await smartAccount.syncSendTransaction({
to: anotherAddress,
value: 10n,
gas: 100000n,
});
await tx.wait();

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:643


calculateSmartAccountAddress()

static calculateSmartAccountAddress(param0): 0x${string}

Calculates the address of the new smart account.

Parameters

ParameterTypeDescription

param0

object

The object representing the config for address calculation.

param0.pubKey

Uint8Array<ArrayBufferLike>

The smart account public key.

param0.salt

bigint | Uint8Array<ArrayBufferLike>

Arbitrary data change the address.

param0.shardId

number

The ID of the shard where the smart account should be deployed.

Returns

0x${string}

The address of the new smart account.

Static

Example

import {
LocalECDSAKeySigner,
SmartAccountV1,
generateRandomPrivateKey,
} from '@nilfoundation/niljs';

const signer = new LocalECDSAKeySigner({
privateKey: generateRandomPrivateKey(),
});

const pubkey = signer.getPublicKey();

const anotherAddress = SmartAccountV1.calculateSmartAccountAddress({
pubKey: pubkey,
shardId: 1,
salt: 200n,
});

Defined

@nilfoundation/niljs/src/smart-accounts/SmartAccountV1/SmartAccountV1.ts:84