> ## Documentation Index
> Fetch the complete documentation index at: https://docs.chipipay.com/llms.txt
> Use this file to discover all available pages before exploring further.

# callAnyContract

> Executes any StarkNet contract method. Handles all contract interactions not covered by specific methods, giving you full flexibility to interact with any smart contract.

## Usage

```typescript theme={null}
const bearerToken = await getBearerToken(); // Your auth implementation

const result = await browserClient.callAnyContract({
  params: {
    encryptKey: "user-secure-pin",
    wallet: {
      publicKey: "0x123...yourPublicKeyHere",
      encryptedPrivateKey: "encrypted:key:data"
    },
    calls: [
      {
        contractAddress: "0x...", // Target contract address
        entrypoint: "methodName", 
        calldata: ["param1", "param2"] 
      }
    ],
  },
  bearerToken: bearerToken,
});
```

### Parameters

* `encryptKey` (string): User's decryption PIN
* `wallet` (WalletData): Wallet credentials with publicKey and encryptedPrivateKey
* `calls` (array): Array of contract calls to execute
  * `contractAddress` (string): Target contract address
  * `entrypoint` (string): Contract method name
  * `calldata` (any\[]): Arguments for the contract method
* `bearerToken` (string): Bearer token for authentication

### Return Value

Returns a Promise that resolves to a transaction hash string.

## Example Implementation

```typescript theme={null}
import { ChipiBrowserSDK } from "@chipi-stack/backend";

const browserClient = new ChipiBrowserSDK({
  apiPublicKey: process.env.VITE_CHIPI_PUBLIC_KEY, // or your framework's env var
});

async function executeContractCall(
  wallet: { publicKey: string; encryptedPrivateKey: string },
  contractAddress: string,
  methodName: string,
  parameters: any[],
  userPin: string
) {
  try {
    const bearerToken = await getBearerToken(); // Your auth implementation
    
    const result = await browserClient.callAnyContract({
      params: {
        encryptKey: userPin,
        wallet: wallet,
        calls: [
          {
            contractAddress: contractAddress,
            entrypoint: methodName,
            calldata: parameters,
          }
        ],
      },
      bearerToken: bearerToken,
    });

    console.log('Contract call successful!');
    console.log('Transaction hash:', result);
    
    return result;
  } catch (error) {
    console.error('Contract call failed:', error);
    throw error;
  }
}

// Usage example - Approve tokens for spending
async function approveTokenSpending(
  userId: string,
  tokenContract: string,
  spenderAddress: string,
  amount: string,
  pin: string
) {
  const bearerToken = await getBearerToken();
  
  // Get user's wallet
  const wallet = await browserClient.getWallet({
    externalUserId: userId,
    bearerToken: bearerToken,
  });

  // Call the approve method on the token contract
  const txHash = await executeContractCall(
    wallet,
    tokenContract,
    "approve",
    [spenderAddress, amount, "0"], // StarkNet uses felt252 for amounts
    pin
  );

  console.log(`Approved ${amount} tokens for ${spenderAddress}`);
  return txHash;
}
```

## Related Methods

* [transfer](/sdk/other-frontend/methods/transfer) - For simple token transfers
* [getWallet](/sdk/other-frontend/methods/get-wallet) - Get wallet information before contract calls
