Skip to main content

Class: WalletV1

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

WalletV1

Constructors​

new WalletV1()​

new WalletV1(param0): WalletV1

Creates an instance of WalletV1.

Parameters​

ParameterTypeDescription

param0

WalletV1Config

The object representing the initial wallet config. See WalletV1Config.

Returns​

WalletV1

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:144

Properties​

address​

address: Uint8Array;

The wallet address.

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:130


client​

client: PublicClient;

The client for interacting with the wallet.

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:112


pubkey​

pubkey: Uint8Array;

The wallet public key.

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:100


salt?​

optional salt: Uint8Array;

Arbitrary data for changing the wallet address.

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:118


shardId​

shardId: number;

The ID of the shard where the wallet is deployed.

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:106


signer​

signer: ISigner;

The wallet signer.

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:124


abi​

static abi: Abi;

The wallet ABI.

Static​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:42


code​

static code: Uint8Array;

The wallet bytecode.

Static​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:35

Methods​

checkDeploymentStatus()​

checkDeploymentStatus(): Promise<boolean>

Checks the deployment status.

Returns​

Promise<boolean>

The current deployment status.

Async​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:270


deployContract()​

deployContract(param0): Promise<object>

Deploys a new smart contract via the wallet.

Parameters​

ParameterTypeDescription

param0

DeployParams

The object representing the contract deployment params.

Returns​

Promise<object>

The object containing the deployment message hash and the contract address.

address​
address: `0x${string}`;
hash​
hash: `0x${string}`;

Async​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:412


getAddressHex()​

getAddressHex(): `0x${string}`

Converts the wallet address into a hexadecimal.

Returns​

`0x${string}`

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:177


getBalance()​

getBalance(): Promise<bigint>

Returns the wallet balance.

Returns​

Promise<bigint>

The wallet balance.

Async​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:521


requestToWallet()​

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

Performs a request to the wallet.

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 message bytecode and hash.

hash​
hash: Uint8Array;
raw​
raw: Uint8Array;

Async​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:283


selfDeploy()​

selfDeploy(waitTillConfirmation?): Promise<Uint8Array>

Deploys the wallet.

Parameters​

ParameterTypeDefault valueDescription

waitTillConfirmation?

boolean

true

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

Returns​

Promise<Uint8Array>

The hash of the deployment transaction.

Async​

Example​

import {
Faucet,
HttpTransport,
LocalECDSAKeySigner,
PublicClient,
WalletV1,
generateRandomPrivateKey,
} from '@nilfoundation/niljs';
const client = new PublicClient({
transport: new HttpTransport({
endpoint: "http://127.0.0.1:8529",
}),
shardId: 1,
});
const signer = new LocalECDSAKeySigner({
privateKey: generateRandomPrivateKey(),
});
const faucet = new Faucet(client);
await faucet.withdrawTo(walletAddress, 100000n);
const pubkey = await signer.getPublicKey();
const wallet = new WalletV1({
pubkey: pubkey,
salt: 100n,
shardId: 1,
client,
signer,
address: WalletV1.calculateWalletAddress({
pubKey: pubkey,
shardId: 1,
salt: 100n,
}),
});
await wallet.selfDeploy(true);

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:222


sendMessage()​

sendMessage(param0): Promise<`0x${string}`>

Send a message via the wallet.

Parameters​

ParameterTypeDescription

param0

SendMessageParams

The object representing the message params.

Returns​

Promise<`0x${string}`>

The message hash.

Async​

Example​

const anotherAddress = WalletV1.calculateWalletAddress({
pubKey: pubkey,
shardId: 1,
salt: 200n,
});
await wallet.sendMessage({
to: anotherAddress,
value: 10n,
gas: 100000n,
});

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:334


sendRawInternalMessage()​

sendRawInternalMessage(rawMessage): Promise<`0x${string}`>

Send a raw signed message via the wallet.

Parameters​

ParameterTypeDescription

rawMessage

Uint8Array

The message bytecode.

Returns​

Promise<`0x${string}`>

The message hash.

Async​

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:387


syncSendMessage()​

syncSendMessage(param0): Promise<`0x${string}`>

Send a message synchronously via the wallet.

Parameters​

ParameterTypeDescription

param0

SendSyncMessageParams

The object representing the message params.

Returns​

Promise<`0x${string}`>

The message hash.

Async​

Example​

const anotherAddress = WalletV1.calculateWalletAddress({
pubKey: pubkey,
shardId: 1,
salt: 200n,
});
await wallet.sendMessage({
to: anotherAddress,
value: 10n,
gas: 100000n,
});

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:486


calculateWalletAddress()​

static calculateWalletAddress(param0): Uint8Array

Calculates the address of the new wallet.

Parameters​

ParameterTypeDescription

param0

object

The object representing the config for address calculation.

param0.pubKey

Uint8Array

The wallet public key.

param0.salt

bigint | Uint8Array

Arbitrary data change the address.

param0.shardId

number

The ID of the shard where the wallet should be deployed.

Returns​

Uint8Array

The address of the new wallet.

Static​

Example​

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

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

const pubkey = await signer.getPublicKey();

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

Defined in​

nil/nil.js/src/contracts/WalletV1/WalletV1.ts:76