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

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:149

Properties

address

address: Uint8Array;

The wallet address.

Defined

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


client

client: PublicClient;

The client for interacting with the wallet.

Defined

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


pubkey

pubkey: Uint8Array;

The wallet public key.

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:105


salt?

optional salt: Uint8Array;

Arbitrary data for changing the wallet address.

Defined

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


shardId

shardId: number;

The ID of the shard where the wallet is deployed.

Defined

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


signer

signer: ISigner;

The wallet signer.

Defined

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


abi

static abi: Abi;

The wallet ABI.

Static

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:47


code

static code: Uint8Array;

The wallet bytecode.

Static

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:40

Methods

burnCurrency()

burnCurrency(amount): Promise<any>

Burns the currency that the wallet owns.

Parameters

ParameterType

amount

bigint

Returns

Promise<any>

The message hash.

Async

Example

const hashMessage = await wallet.burnCurrency(burnCurrency);
await waitTillCompleted(client, 1, hashMessage);

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:437


checkDeploymentStatus()

checkDeploymentStatus(): Promise<boolean>

Checks the deployment status.

Returns

Promise<boolean>

The current deployment status.

Async

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:275


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: any;
hash
hash: any;

Async

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:493


getAddressHex()

getAddressHex(): any

Converts the wallet address into a hexadecimal.

Returns

any

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:182


getBalance()

getBalance(): Promise<bigint>

Returns the wallet balance.

Returns

Promise<bigint>

The wallet balance.

Async

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:604


mintCurrency()

mintCurrency(amount): Promise<any>

Mints the currency that the wallet owns and withdraws it to the wallet. setCurrencyName has to be called first before minting a currency.

Parameters

ParameterType

amount

bigint

Returns

Promise<any>

The message hash.

Async

Example

const hashMessage = await wallet.mintCurrency(mintCount);
await waitTillCompleted(client, 1, hashMessage);

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:423


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

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:288


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: RPC_ENDPOINT,
}),
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

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:227


sendMessage()

sendMessage(param0): Promise<any>

Send a message via the wallet.

Parameters

ParameterTypeDescription

param0

XOR<SendDataMessageParams, SendAbiMessageParams>

The object representing the message params.

Returns

Promise<any>

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

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:342


sendRawInternalMessage()

sendRawInternalMessage(rawMessage): Promise<any>

Send a raw signed message via the wallet.

Parameters

ParameterTypeDescription

rawMessage

Uint8Array

The message bytecode.

Returns

Promise<any>

The message hash.

Async

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:468


setCurrencyName()

setCurrencyName(name): Promise<any>

Sets the name of the custom currency that the wallet can own and mint.

Parameters

ParameterType

name

string

Returns

Promise<any>

The message hash.

Async

Example

const hashMessage = await wallet.setCurrencyName("MY_TOKEN");
await waitTillCompleted(client, 1, hashMessage);

Defined

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:397


syncSendMessage()

syncSendMessage(param0): Promise<any>

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

Parameters

ParameterTypeDescription

param0

XOR<SendSyncDataMessageParams, SendSyncAbiMessageParams>

The object representing the message params.

Returns

Promise<any>

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

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:570


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

@nilfoundation/niljs/src/contracts/WalletV1/WalletV1.ts:81