TS Library
Now that your testnet RPC server is up, let's interact with your contract using the ts-library. The concept is similar to qubic-cli: we craft the packet and send it to the node—but this time, we'll use code instead. However, a current limitation is that we still need to represent input and output as byte arrays in JavaScript and manually parse the response bytes to construct the output. Let’s see how this works!
Concept
Any packet sent to the Qubic network must begin with a RequestResponseHeader, which describes metadata such as the packet type and its total size. Similarly, responses from a Qubic node will also start with a RequestResponseHeader.
The QubicPackageBuilder class is a helper for combining the RequestResponseHeader with other structures.
Each RequestResponseHeader must include a unique dejavu.
Calling Function
Show getStateNumber Contract Function
struct getStateNumber_input
{
};
struct getStateNumber_output
{
uint64 stateNumber;
};
PUBLIC_FUNCTION(getStateNumber)
{
output.stateNumber = state.stateNumber;
}
Instead of manually crafting and sending the packet, the RPC server provides a convenient API at /v1/querySmartContract which allows us to make a POST request to invoke a function and receive a result. Let's see how to call the getStateNumber contract function described above.
The input (body) and output (response) of /v1/querySmartContract must be encoded in base64 format.