Sats Connect - Wallet API for Bitcoin & Stacks
  • Introduction
  • Wallet Providers
    • getInfo
    • getProviders & getProviderById
  • Connecting to the wallet
    • Connect to Xverse Wallet
    • Disconnect from Xverse Wallet
    • Connect to other wallets
      • Manage a user's default wallet
    • [Legacy ⚠️] getAccounts
  • Wallet Methods
    • request methods
    • wallet_getAccount
    • wallet_getNetwork
    • wallet_changeNetwork
    • Xverse Custom Methods
  • Xverse Wallet Permissions
  • Xverse Wallet events
  • BITCOIN METHODS
    • 🟠getAddresses
    • 🟠signMessage
    • 🟠signPsbt
    • 🟠sendTransfer
    • 🟠signMultipleTransactions
    • 🟠getBalance
    • 🎨createInscription
    • 🎨createRepeatInscriptions
    • 🎨ord_getInscriptions
    • 🎨ord_sendInscriptions
    • 🔲runes_getBalance
    • 🔲runes_transfer
    • 🔲Mint Runes
      • runes_estimateMint
      • runes_mint
    • 🔲Etch Runes
      • runes_estimateEtch
      • runes_etch
    • 🔲runes_getOrder
    • 🔲Speed up a Rune Mint or Etch order
      • 🔲runes_estimateRbfOrder
      • 🔲runes_rbfOrder
  • STACKS METHODS
    • 🔴stx_getAccounts
    • 🔴stx_signMessage
    • 🔴stx_signStructuredMessage
    • 🔴stx_transferStx
    • 🔴stx_signTransaction
    • 🔴stx_callContract
    • 🔴stx_deployContract
  • GUIDES
    • Verify Bitcoin message signatures
    • Creating Bitcoin PSBTs
    • 📱Mobile Integration
    • Next.js support
  • RESOURCES
    • App Template
    • Demo App
    • Changelog
    • Github Issues
    • Developer forum
    • BIP322
Powered by GitBook
On this page
  1. STACKS METHODS

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

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.

functionArgs

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.

postConditions

an array of strings representing the post conditions to be applied on the transaction. post conditions are expected as hex-encoded strings

To convert post conditions values to their hex representation, you can use the postConditionToHex helper from the @stacks/transactions package.

postConditionMode

a string representing the post condition mode to evaluate post-conditions:

  • allow -> in "allow" mode, other asset transfers not covered by the post-conditions are permitted

  • deny -> in "deny" mode, no other asset transfers are permitted besides those named in the post-conditions.

    import { request } from "sats-connect";

      const response = await request("stx_callContract", {
        contract: `${contractAddress}.${contractName}`,
        functionName,
        functionArgs: 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

Previousstx_signTransactionNextstx_deployContract

Last updated 1 month ago

arguments Deprecated

This request param is now deprecated. Use functionArgs.

🔴
import { cvToString } from '@stacks/transactions';
const functionArgs = [someClarityValue1, someClarityValue2];
const hexArgs = functionArgs.map(cvToString);
import { cvToString } from '@stacks/transactions';
const functionArgs = [someClarityValue1, someClarityValue2];
const hexArgs = functionArgs.map(cvToString);
⚠️
⚠️