pendulum-chain / api-solang

This is the code for the npm package @pendulum-chain/api-solang
0 stars 0 forks source link

Polkadot API for Smart Contracts compiled via Solang

This library allows to deploy and call into smart contracts that have been compiled from Solidity to wasm via Solang.

It has three main functions:

These functions are meant to be used very flexibly and they have the following special features:

  1. The first two functions allow to either specify a keypair or a general signer in order to sign the extrinsics. The keypair is generally useful for command line tools whereas the signer is more useful in a browser context, where it can give access to a wallets or browser extensions.

  2. In certain applications it can be necessary to extend the extrinsics created in the first two functions, e.g., to wrap them into a sudo call. For that reason these functions allow to specify an optional argument modifyExtrinsic that allows the caller to arbitrarily change or extend the created extrinsic.

  3. Contracts usually emit events and these events can be emitted by contracts (recursively) called by the original contract. In order to properly decode the binary data contained in the event, one needs to lookup the abi of the respective contract emitting the event. For that reason the first two functions take an optional argument lookupAbi that allows the caller to provide the abi for any deployed contract (identified through the contract address).

  4. All functions can correctly decode the return value of message calls, i.e., whether a message call reverted (including the revert message) or whether it panicked and why it panicked.

The differences between the message call by extrinsic and the message call by RPC methods are:

Deploy a smart contract

The function deployContract has the following arguments:

The return value of this function is an object that contains the field type. This fields indicate the execution status and is either one of the values:

Execute a Message Call

The function executeMessage has the following arguments:

The return value of this function is an object that contains two entries execution and result. The execution entry contains the field type, which can be either one of

The result object contains the entry gasMetrics with the sub entries gasRequired and gasConsumed (both are a Weight). Furthermore, it has the field type which is either one of the following values:

Dry Run a Message Call (Read Message)

The function readMessage has the following arguments:

The return value of this function contains the entry gasMetrics with the sub entries gasRequired and gasConsumed (both are a Weight). Furthermore, it has the field type which is either one of the following values:

Submit an Extrinsic

Additionally this module also exposes a function signAndSubmitExtrinsic that allows to submit an arbitrary extrinsic and that processes the chain events in order to determine the execution status of the extrinsic.

It has two arguments:

This function only returns after the extrinsic has been executed on-chain. The return value of this function is an object with the following entries: