krnl-sdk
TypeScript icon, indicating that this package has built-in type declarations

0.0.5 • Public • Published

krnl-sdk

A fork of ethers.js with two additional functionalities for enhanced smart contract interactions.

Setup

Documentation: https://docs.platform.lat/

const provider = new ethers.JsonRpcProvider(process.env.KRNL_RPC_ENDPOINT);

Features

1. Get Kernel Cost

This method fetches the cost related to a kernel.

provider.getKernelsCost(ENTRY_ID: string)

returns

{
    cost: string,
    rate: string,
    cost_precision: number,
    rate_precision: number
}

2. Execute Kernels

This method allows you to execute kernels with Web2 or Web3 calls.

kernelRequestData ={
    senderAddress: string,
    kernelPayload = {
        [id: number]: {
            parameters?: {
            header?: Record<string, string>;
            body?: Record<string, any>;
            query?: Record<string, string>;
            path?: Record<string, string>;
        };
        functionParams?: any[];
         };
    };  
}

Function Parameters: For Web3 calls, the functionParams array should contain parameters in hex-encoded format according to the contract's ABI. However, because the kernelPayload needs to be retrieved first, use a low-level ABI encoder to handle this. Make sure to exclude the auth structure from the encoding process.

    const abiEncoder =AbiCoder.defaultAbiCoder();

    const encodedData = abiEncoder.encode(types, [param1, param2, ....]);
    console.log("Encoded key and value:", encodedData);

Note: If there are no arguments, you can leave the functionParams blank.

Execute Kernels Example:

provider.executeKernels(
    entryID: string,
    accessToken: string,
    kernelRequestData,
    functionParams
);

returns

{
    "kernel_params": "string",
    "kernel_responses": "string",
    "auth": "string"
}

Note: The function parameters are already ABI-encoded. Do not re-encode them while executing protected functionalities.

Example: Executing a Protected Function

const krnlPayload = {
    auth: executionResults.auth,
    kernelResponses: executionResults.kernel_responses,
    kernelParamObjects: executionResults.kernel_params,
};

const tx = await contract.protectedFunction(krnlPayload, param1, param2, ...);

Documentation

For the core functionalities, please refer to the ethers.js docs.

Package Sidebar

Install

npm i krnl-sdk

Homepage

krnl.xyz

Weekly Downloads

227

Version

0.0.5

License

MIT

Unpacked Size

12.6 MB

Total Files

1271

Last publish

Collaborators

  • runkrnl
  • devopskrnl
  • reiss-krnl
  • speedkrnl
  • umtkrnl