Skip to main content
Last updated

Built-in utilities

The @kadena/client-utils library includes several modules to provide a TypeScript-based application programming interface (API) for interacting with Pact smart contracts and the Kadena network. The built-in module provides basic functions to return module descriptions and create principal accounts. These functions are broadly useful for any type of application that access the Kadena blockchain.

Before you begin

You must have node.js and npm, or an equivalent package manager, installed in your development environment. You can run the following commands to check whether node and npm are installed locally:

bash
node --versionnpm --version
bash
node --versionnpm --version

Install

You can install the @kadena/client-utils library with the following command:

bash
npm install @kadena/client-utils
bash
npm install @kadena/client-utils

After you download the latest package, you can import built-in functions into TypeScript programs with statements similar to the following example:

typescript
import { describeModule } from '@kadena/client-utils/built-in';
typescript
import { describeModule } from '@kadena/client-utils/built-in';

createPrincipal

Use createPrincipal to create a principal account based on one public key. By default, the principal account is always assigned the keys-all predicate function.

typescript
createPrincipal(keyset)
typescript
createPrincipal(keyset)

Parameters

ParameterTypeDescription
keysetobjectSpecifies the public for the single owner of the principal account and, optionally, the predicate function.

Return value

This function returns the principal account as a string.

Example

The following example illustrates how to use the createPrincipal function in a TypeScript program:

typescript
TBD
typescript
TBD

deployContract

Use deployContract to deploy a Pact module on a specific Kadena network and chain.

typescript
deployContract(contractCode, transactionBody)
typescript
deployContract(contractCode, transactionBody)

Parameters

ParameterTypeDescription
contractCodeobjectSpecifies the contract you want to deploy.
transactionBodyobjectSpecifies the transaction properties.

The transactionBody object contains the following properties:

json
{  chainId: string,  networkId: string,  signers: [list],  meta: {    gasLimit: integer,    chainId: string,    ttl: integer,    senderAccount: string,  }}
json
{  chainId: string,  networkId: string,  signers: [list],  meta: {    gasLimit: integer,    chainId: string,    ttl: integer,    senderAccount: string,  }}

Return value

This function returns a boolean value to indicate whether the contract was successfully deployed or failed.

Example

The following example illustrates how to use the deployContract function in a TypeScript program:

typescript
TBD
typescript
TBD

describeModule

Use describeModule to return detailed information about a specified Pact module.

typescript
describeModule(module)
typescript
describeModule(module)

Parameters

ParameterTypeDescription
modulestringSpecifies the name of the module to describe.

Return values

This function returns the IDescribeModuleOutput object the following properties:

 {
  hash: string;
  blessed: string[];
  keyset: string;
  interfaces: string[];
  name: string;
  code: string;
}

Example

The following example illustrates how to use the describeModule function in a TypeScript program:

typescript
TBD
typescript
TBD

listModules

Use listModules to list the Pact module currently available in the network that you're connected to.

listModules

Return values

This function returns a list of module names.

Example

The following example illustrates how to use the listModule function in a TypeScript program:

typescript
TBD
typescript
TBD