A fork of ethers.js
with two additional functionalities for enhanced smart contract interactions.
Documentation: https://docs.platform.lat/
const provider = new ethers.JsonRpcProvider(process.env.KRNL_RPC_ENDPOINT);
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
}
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.
const krnlPayload = {
auth: executionResults.auth,
kernelResponses: executionResults.kernel_responses,
kernelParamObjects: executionResults.kernel_params,
};
const tx = await contract.protectedFunction(krnlPayload, param1, param2, ...);
For the core functionalities, please refer to the ethers.js docs.