Skip to content

createDaccWallet

A function to create a Wallet

The createDaccWallet function is the cornerstone of dacc-js. Its primary role is to generate a new wallet, encrypt its Private Key using the user's password, and return the wallet's public address along with the encrypted key for secure storage.

Import

import { createDaccWallet } from 'dacc-js';

Usage

import { createDaccWallet } from 'dacc-js';
 
const wallet = await createDaccWallet({
 passwordSecretkey: 'my+Password#123..',
//  publicEncryption: true,
//  dataStorageNetwork: 'opSepolia',
//  pkWalletForSaveData: 'ENV.0XPRIVATEKEY_GAS..',
//  minPassword: 24
});
 
console.log("wallet:", wallet); // {address, daccPublickey}
console.log("wallet address:", wallet?.address); // 0x123address... (recall)
console.log("wallet daccPublickey:", wallet?.daccPublickey); // daccPublickey_XxX... (keep)

Arguments

ParameterTypeDescription
passwordSecretkeystringThe user's password used as the key for encryption.
publicEncryptionbooleanEnable or disable public encryption (default: false). default: false, no retrospective recording will be performed with readDaccWallet.
dataStorageNetworkstring (keyof) - SELECT or customChain{}The blockchain network (e.g., 'opSepolia') to store the encrypted data is on-chain.
pkWalletForSaveData0x${string}The Private Key of an existing wallet used to pay for gas when submitting the encrypted data to the blockchain (required if dataStorageNetwork is set).
minPassword, maxPasswordnumberOptional settings to define the minimum/maximum password length (defaults: 6 and 64).

Return Value

The response result is an object containing. {address, daccPublickey}

Parameters

passwordSecretkey

  • Type: string

You set a password.

const wallet = await createDaccWallet({
 passwordSecretkey: 'myPassword#123...', 
});

publicEncryption (optional)

  • Type: boolean
  • Default: false

Configure the public encryption mode setting.

const wallet = await createDaccWallet({
 passwordSecretkey: 'my+Password#123...',
 publicEncryption: true // default = false
 dataStorageNetwork: 'opSepolia', // required for this mode
 pkWalletForSaveData: 'ENV.0XPRIVATEKEY_GAS...' // required for this mode
});

dataStorageNetwork (optional)

  • Type: string (keyof) | customChain{ chain: Chain, contract: 0x${string}}

Select supported networks.

const wallet = await createDaccWallet({
 passwordSecretkey: 'myPassword#123...', 
 publicEncryption: true, // required for this mode
 dataStorageNetwork: 'opSepolia', 
//   dataStorageNetwork: { 
//     customChain: { // For Custom Chain Network
//       chain: myCustomChain, 
//       contract: "0xYourDeployDaccWalletStorageOnChainAddress..",
//     }, 
//   },
 pkWalletForSaveData: 'ENV.0XPRIVATEKEY_GAS...', // required for this mode
});

pkWalletForSaveData (optional)

  • Type: 0x${string}

Specify a private key for the wallet creation to save the public key encryption data retrospectively.

const wallet = await createDaccWallet({
 passwordSecretkey: 'myPassword#123...', 
 dataStorageNetwork: 'opSepolia', 
 pkWalletForSaveData: 'ENV.0XPRIVATEKEY_GAS..', // ENV.SECRET
});

minPassword & maxPassword (optional)

  • Type: number
  • Default: 12 (min), 120 (max)

Configure the password length setting.

const wallet = await createDaccWallet({
 passwordSecretkey: 'myPassword#123',
//  publicEncryption: true,
//  dataStorageNetwork: 'opSepolia', 
//  pkWalletForSaveData: '0xprivatekeyGas..',
 minPassword: 24 // default = 12
 maxPassword: 240 // default = 120
});