Nexion21
Nexion21

Reputation: 339

How do you call non-write functions from a module without needing to pay gas, using pact-lang-api?

I have a few simple functions that get data from the blockchain, which normally does not require sending a transaction when using Chainweaver.

(defun get-price (price-key:decimal)
    (at "price" (read price-table price-key ["price"]
)

This function does not change any data, so it shouldn't require gas. How can I use something like the x-wallet browser plugin to call this function and just get the data?

Upvotes: 2

Views: 68

Answers (1)

Kitty Kad
Kitty Kad

Reputation: 444

You can just call the local API via HTTP request.

I.e.

localRes = await fetch(
   `${networkUrl}/api/v1/local`, 
  {
    headers: {
      "Content-Type": "application/json",
    },
    method: "POST",
    body: JSON.stringify(cmd),
  };
);

Note: For the cmd - you need to make a valid pact-lang-api command which specifies the smart contract and method to call

Upvotes: 2

Related Questions