🔴stx_callContract

You can use the stx_callContract method to request the signature of any contract call transaction from the user's wallet. The method lets you specify the contract to call, the function to execute on the contract and the arguments to pass to the function.

Request parameters
Description

contract

a string representing the contract's Crockford base-32 encoded Stacks address, and the contract name, separated by a . Example: ST000000000000000000002AMW42H.pox-3

functionName

a string representing the name of the contract function to call

arguments

an array of strings representing the arguments to pass to the function called. The arguments are expected as hex-encoded strings of Clarity values.

To convert Clarity values to their hex representation, you can use the cvToStringhelper from the @stacks/transactions package.

    import { request } from "sats-connect";

      const response = await request("stx_callContract", {
        contract: `${contractAddress}.${contractName}`,
        functionName,
        arguments: JSON.parse(functionArgs),
      });
      if (response.status === "success") {
        console.log(response.result);
      } else {
        console.error(response.error);
      }
    } catch (error) {
      console.error(error);
      alert(error);
    }

The user will see a Stacks contract call transaction signing request prompt in the wallet.

The transaction will be signed and broadcasted upon user approval.

The stx_callContract method returns a Promise that resolves to the CallContractResult object:

Property
Description

txid

a hex-encoded string representing the ID of the Stacks contract call transaction signed

transaction

a hex-encoded string representing the Stacks contract call transaction signed

Last updated