Skip to main content

Usage

Simple transaction

await callSmartContract({
  contracts: [
    {
      contractAddress: "0x1234567890123456789012345678901234567890",
      functionName: "transfer",
      functionParams: ["0x0987654321098765432109876543210987654321", "1000000"],
      value: "0",
    },
  ],
});

Batch transaction

await callSmartContract({
  contracts: [
    {
      contractAddress: "0x1234567890123456789012345678901234567890",
      functionName: "transfer",
      functionParams: ["0x0987654321098765432109876543210987654321", "1000000"],
      value: "0",
    },
    {
      contractAddress: "0x1234567890123456789012345678901234567890",
      functionName: "deposit",
      functionParams: ["0x0987654321098765432109876543210987654321", "1000000"],
      value: "0",
    },
  ],
});

Values for title and description

await callSmartContract({
  contracts: [
    {
      contractAddress: "0x1234567890123456789012345678901234567890",
      functionName: "transfer",
      functionParams: ["0x0987654321098765432109876543210987654321", "1000000"],
      value: "0",
    },
  ],
  titleValues: {
    amount: "100",
    token: "USDC",
  },
  descriptionValues: {
    recipient: "0x0987654321098765432109876543210987654321",
    network: "Polygon",
  },
});

Parameters

type CallSmartContractInput {
  contractAddress: '0x${string}';
  functionName: string;
  functionParams: string | number[];
  value: string;
  contractStandard?: ContractStandard;
  chainId?: ChainId;
  permits?: Permit[];
  titleValues?: Record<string, string>;
  descriptionValues?: Record<string, string>;
}
contractAddress
0x${string}
required
The address of the smart contract to interact with.
functionName
string
required
The name of the smart contract function to call.
functionParams
string | number[]
required
The parameters to pass to the smart contract function. Should be an empty array if no parameters are needed.
value
string
required
The amount of native currency (ETH, POL, etc.) to send with the transaction. Specify ‘0’ if no native token is transferred.
contractStandard
ContractStandard
The contract standard if any (e.g., ‘ERC20’).
chainId
ChainId
If your Mini App supports multiple chains, you can specify the chain id to use.
permits
Permit[]
Optional array of Permit2 permits for token approvals. Each permit must include: - owner: The address of the user wallet that owns the tokens. - token: The address of the ERC20 token to be approved. - spender: The address of the contract authorized to spend the tokens (must match the contractAddress). - amount: The maximum amount that can be spent, in the token’s smallest unit (e.g., wei). - deadline: UNIX timestamp (in seconds) after which the permit expires. - nonce: Unique nonce (number) to prevent replay attacks.
titleValues
Record<string, string>
Optional values to interpolate into the method title. Use {{key}} placeholders in the method title, and provide the corresponding values here.Note: Any unreplaced placeholders (those without a corresponding value) will be automatically removed from the final text.Example: If the title is “Swap {{amount}} {{token}}”, pass { amount: "100", token: "USDC" } to display “Swap 100 USDC”. If you only pass { amount: "100" }, it will display “Swap 100” (the {{token}} placeholder is removed).
descriptionValues
Record<string, string>
Optional values to interpolate into the method description. Use {{key}} placeholders in the method description configuration, and provide the corresponding values here.Note: Any unreplaced placeholders (those without a corresponding value) will be automatically removed from the final text.Example: If the description is “Exchange {{fromToken}} for {{toToken}}”, pass { fromToken: "USDC", toToken: "ETH" } to display “Exchange USDC for ETH”.

Returns

type CallSmartContractResponse = {
  result: TransactionResult.SUCCESS;
  data: {
    txHash: string;
  };
} | {
  result: TransactionResult.FAILED;
  error: MiniAppError;
} | {
  result: TransactionResult.CANCELLED;
}
result
TransactionResult
The result of the smart contract call attempt. - SUCCESS: The smart contract call was successful. - FAILED: The smart contract call failed. - CANCELLED: The smart contract call was cancelled by the user.
data
object
Contains the transaction hash of the smart contract call transaction. Only present when the result is SUCCESS. - txHash: The transaction hash.
error
MiniAppError
Contains the error information when the smart contract call fails. Only present when the result is FAILED. - message: The error message. - code: The error code.

Demo

Example using Permit2

Instead of requiring a user to submit a separate approve transaction before a contract can interact with their tokens, you can provide a signed permit. The service will automatically handle the one-time approval to the Permit2 contract if it hasn’t been done already.
await callSmartContract({
  contracts: [
    {
      contractAddress: "0xDeFiProtocolContract...",
      functionName: "depositWithPermit",
      args: ["1000000000000000000", "PERMIT_PLACEHOLDER_0"],
      value: "0",
      chainId: ChainId.POLYGON,
      permits: [
        {
          owner: wallet,
          token: "0xTokenAddress...",
          spender: "0xDeFiProtocolContract...",
          amount: "1000000000000000000",
          deadline: "1735689600",
          nonce: "0",
        },
      ],
    },
  ],
});

Permit Type

type Permit = {
  owner: Address; // User's wallet address
  token: Address; // ERC20 token address
  spender: Address; // Contract that will spend the tokens
  amount: string; // Amount in smallest unit (wei)
  deadline: string; // Unix timestamp in seconds
  nonce: string; // Unique number
};

Using Permits

The SDK automatically handles all Permit2 complexity for you. You simply provide the permit data, and the SDK will:
  1. Generate the EIP-712 signature
  2. Handle the one-time ERC-20 approval to Permit2 if needed
  3. Execute the transaction with the permit signature
Related resources: