Skip to main content

Class: SmartAccountV1

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

SmartAccountV1

Implements

  • SmartAccountInterface

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/contracts/SmartAccountV1/SmartAccountV1.ts:155

Properties

address

address: 0x${string};

The smart account address.

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:141


client

client: PublicClient;

The client for interacting with the smart account.

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:123


pubkey

pubkey: Uint8Array;

The smart account public key.

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:111


salt?

optional salt: Uint8Array;

Arbitrary data for changing the smart account address.

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:129


shardId

shardId: number;

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

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:117


signer

signer: ISigner;

The smart account signer.

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:135


abi

static abi: any = SmartAccount.abi;

The smart account ABI.

Static

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:52


code

static code: Uint8Array;

The smart account bytecode.

Static

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:45

Methods

burnToken()

burnToken(amount): Promise<any>

Burns the token that the smart account owns.

Parameters

ParameterType

amount

bigint

Returns

Promise<any>

The transaction hash.

Async

Example

const hashTransaction = await smartAccount.burnToken(burnToken);
await waitTillCompleted(client, hashTransaction);

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:470


checkDeploymentStatus()

checkDeploymentStatus(): Promise<boolean>

Checks the deployment status.

Returns

Promise<boolean>

The current deployment status.

Async

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:286


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 hash and the contract address.

address
address: any;
hash
hash: any;

Async

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:526


getBalance()

getBalance(): Promise<bigint>

Returns the smart account balance.

Returns

Promise<bigint>

The smart account balance.

Async

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:689


mintToken()

mintToken(amount): Promise<any>

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<any>

The transaction hash.

Async

Example

const hashTransaction = await smartAccount.mintToken(mintCount);
await waitTillCompleted(client, hashTransaction);

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:456


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;
raw
raw: Uint8Array;
seqno
seqno: number;

Async

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:299


selfDeploy()

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

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<Uint8Array>

The hash of the deployment transaction.

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/contracts/SmartAccountV1/SmartAccountV1.ts:214


sendRawInternalTransaction()

sendRawInternalTransaction(rawTransaction): Promise<any>

Send a raw signed transaction via the smart account.

Parameters

ParameterTypeDescription

rawTransaction

Uint8Array

The transaction bytecode.

Returns

Promise<any>

The transaction hash.

Async

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:501


sendTransaction()

sendTransaction(param0): Promise<any>

Send a transaction via the smart account.

Parameters

ParameterTypeDescription

param0

XOR<SendDataTransactionParams, SendAbiTransactionParams>

The object representing the transaction params.

Returns

Promise<any>

The transaction hash.

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/contracts/SmartAccountV1/SmartAccountV1.ts:355


setTokenName()

setTokenName(name): Promise<any>

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

Parameters

ParameterType

name

string

Returns

Promise<any>

The transaction hash.

Async

Example

const hashTransaction = await smartAccount.setTokenName("MY_TOKEN");
await waitTillCompleted(client, hashTransaction);

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:430


syncSendTransaction()

syncSendTransaction(param0): Promise<any>

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<any>

The transaction hash.

Async

Example

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

Defined

@nilfoundation/niljs/src/contracts/SmartAccountV1/SmartAccountV1.ts:651


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

The smart account public key.

param0.salt

bigint | Uint8Array

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/contracts/SmartAccountV1/SmartAccountV1.ts:86