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

# Interacting with smart contracts

> Advanced guide to using smart contracts and custom contract interactions from Porto.

Smart contracts are self-executing programs on the blockchain. Porto allows advanced users to interact with any smart contract, from common DeFi protocols to custom enterprise contracts. This guide covers contract interactions, approval management, and best practices.

<Note>
  This page is for advanced users. If you're new to smart contracts, see [Using DApps and smart contracts](/knowledge-base/porto/assets/using-dapps) first.
</Note>

## What is a smart contract interaction

A smart contract interaction is a transaction that:

* Calls a function on a smart contract (not just sending assets)
* May execute complex logic (trading, lending, voting, etc.)
* Can be reverted if something goes wrong (but you still pay gas)
* Requires the contract address and function details to execute

Smart contracts include:

* **DeFi protocols** — Uniswap, Aave, Curve, etc.
* **Governance contracts** — Voting and proposal contracts
* **Bridge contracts** — Cross-chain asset transfers
* **Custom enterprise contracts** — Organizations' internal smart contracts
* **NFT contracts** — Minting, trading, staking contracts

## Connect to a smart contract

There are several ways to interact with smart contracts from Porto:

### Via a DApp interface

Most smart contracts have a user interface (DApp). See [Using DApps](/knowledge-base/porto/assets/using-dapps) for the standard flow.

### Direct contract interaction

For contracts without a user interface:

<Steps>
  <Step title="Prepare contract details">
    You'll need:

    * **Contract address** — The blockchain address of the contract (e.g., 0x...)
    * **Function signature** — The name and parameters of the function you're calling
    * **Contract ABI** — Application Binary Interface (tells Porto how to call the contract)
    * **Parameters** — Values to pass to the function
  </Step>

  <Step title="Open Porto's advanced interaction">
    Look for **Contract interaction**, **Direct contract call**, or **Custom contract** in Porto's settings or advanced menu. This feature may require admin permissions.
  </Step>

  <Step title="Enter contract address">
    Paste the contract address carefully. Verify it matches the official contract (check multiple sources).
  </Step>

  <Step title="Select function">
    If you have the contract ABI, Porto can show you available functions. Otherwise, you'll need to enter the function signature manually.
  </Step>

  <Step title="Enter parameters">
    Fill in the parameters the function requires. Be precise — wrong values will cause the transaction to fail.
  </Step>

  <Step title="Review and approve">
    Porto will show you the transaction details before execution. Review carefully.
  </Step>

  <Step title="Execute">
    Complete biometric authentication to execute the contract call.
  </Step>
</Steps>

## Approvals and token permissions

Many DeFi operations require granting a contract permission to spend your tokens. This happens in two steps:

1. **Approve** — You approve a contract to spend up to a certain amount of a token
2. **Execute** — The contract then uses that allowance to execute the operation

### Approving a token spend

<Steps>
  <Step title="Identify the contract">
    Determine which contract needs approval (usually the DEX or protocol you're using).
  </Step>

  <Step title="Determine the amount">
    Decide how much of your token to approve:

    * **Exact amount** — Approve only what you need for one transaction
    * **High amount** — Approve a large amount for multiple transactions (more convenient, slightly riskier)
    * **Unlimited** — Some users approve unlimited amounts (highest convenience, highest risk)
  </Step>

  <Step title="Submit approval">
    Create an approval transaction. This transaction has no direct effect but grants permission.
  </Step>

  <Step title="Wait for confirmation">
    The approval must confirm on-chain before the next transaction can use it.
  </Step>

  <Step title="Execute your operation">
    Once approved, the contract can execute your transaction (swap, stake, lend, etc.).
  </Step>
</Steps>

## Common smart contract interactions

| Interaction           | Typical function               | Risk   | Gas cost   |
| :-------------------- | :----------------------------- | :----- | :--------- |
| **Swap (DEX)**        | `swap()`, `exactInputSingle()` | Medium | Low-Medium |
| **Stake tokens**      | `stake()`, `deposit()`         | Medium | Low        |
| **Provide liquidity** | `addLiquidity()`, `mint()`     | High   | High       |
| **Borrow**            | `borrow()`, `deposit()`        | High   | Medium     |
| **Vote (governance)** | `vote()`, `castVote()`         | Low    | Low        |
| **Harvest rewards**   | `harvest()`, `claim()`         | Low    | Low        |
| **Bridge transfer**   | `bridge()`, `lock()`           | High   | High       |

## Understanding gas and transaction costs

Every smart contract call costs gas (network fees):

* **Gas price** — Set by the blockchain network (you cannot control this)
* **Gas limit** — Maximum gas this transaction can use (set by the contract or estimated)
* **Total cost** — Gas price × Gas used = Transaction cost

Porto will show you estimated gas costs before execution. Actual costs may vary based on network congestion.

## Recognizing risky contracts

Be cautious of smart contracts that:

* **Lack code verification** — Check if the contract has been audited and code verified on a block explorer
* **Require your private key** — Never share your private key with any contract or off-chain tool
* **Request unusual permissions** — Be suspicious of contracts asking for unlimited approvals
* **Are newly deployed** — New contracts have higher risk of bugs or scams
* **Have no documentation** — Avoid contracts with no clear description of what they do
* **Demand urgent action** — Scams often create artificial time pressure

Always research a contract on community forums and block explorers before using it.

## Reverting failed transactions

If a smart contract transaction fails (reverts):

1. **Check the reason** — Your transaction receipt will show why it failed (insufficient balance, wrong parameters, etc.)
2. **Fix and retry** — Correct the issue and resubmit the transaction
3. **You still pay gas** — Even if the transaction fails, you pay gas fees
4. **Check for slippage** — If swapping, slippage or price impact may have caused failure

## Gas estimation and optimization

Porto estimates gas before you execute a transaction. Tips to reduce gas costs:

* **Lower gas price** — During quiet times, gas is cheaper; use lower gas if you're not in a hurry
* **Batch operations** — Combine multiple interactions into one transaction if possible
* **Use efficient chains** — Layer 2 networks (Arbitrum, Optimism) have much lower gas costs
* **Avoid peak times** — Avoid network peaks when everyone is transacting

## Security best practices

* **Never share your seed phrase** — Even with trusted contracts or platforms
* **Verify contract addresses** — Always check contract addresses from official sources, not user recommendations
* **Use [trusted destinations](/knowledge-base/porto/assets/trusted-destinations)** — For known contracts you use frequently
* **Start small** — Test new contracts with small amounts first
* **Understand the contract** — Read documentation or code before using
* **Keep backups** — Store recovery materials securely in case you need to recover wallets
* **Monitor approvals** — Periodically review contracts you've approved for token spend
* **Revoke unused approvals** — If you no longer use a contract, you can revoke its token approval

## Revoking token approvals

If you've approved a contract but no longer want it to have access:

<Steps>
  <Step title="Identify the contract to revoke">
    Go to a block explorer and find the token contract's approval history, or use a tool like etherscan.io to see all your approvals.
  </Step>

  <Step title="Create revoke transaction">
    Call the token contract's `approve()` function with amount 0 to revoke the approval.
  </Step>

  <Step title="Submit revocation">
    Execute the revoke transaction through Porto or a transaction builder.
  </Step>

  <Step title="Verify revocation">
    Check the block explorer to confirm the approval amount is now 0.
  </Step>
</Steps>

## For organization administrators

If you're managing smart contract interactions for your organization, see your admin settings for:

* Whitelisting specific contracts users can interact with
* Setting approval limits on contract interactions
* Monitoring contract usage across your vaults
* Requiring additional approvals for high-risk contracts
