# Approve Token

{% tabs %}
{% tab title="Code Example" %}
{% code title="approve-token.tsx" %}

```javascript
import {
  approveToken,
  ApproveTypes,
  CHAIN,
  TokenInfo,
  RawTransaction
} from "@ramper-v2/multi";
 
import {
  convertBalanceToWei
} from "@ramper-v2/utils";
 
import Web3 from "web3";
import { CHAIN_DATA } from "@wallet/constants";
 
const rpcURL = CHAIN_DATA[chain].rpcURL;
 
const approveTokenData = {
approveContract: '0x0Fd0288AAAE91eaF935e2eC14b23486f86516c8C',
amount: '1',
spender: '0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826'
}
 
const handleApproveToken = async () => {
  try {
    const {
      approveContract,
      amount: approveAmount,
      spender,
    } = approveTokenData;
 
    if (!approveContract || !chain) return;
 
    const client = new Web3(
      new Web3.providers.HttpProvider(rpcURL)
    );
    const contract = new client.eth.Contract(
      ERC20ABI as any,
      approveContract
    );
 
    const decimal = ramper.config.coinInfo?.[chain]?.find((coinInfo) => {
      return (
        String(coinInfo.address).toLocaleLowerCase() ===
        approveContract.toLocaleLowerCase()
      );
    })?.decimals;
 
    const amount = convertBalanceToWei(approveAmount, decimal);
    const dataraw = contract.methods.approve(spender, amount);
    const rawTransaction: RawTransaction = {
      data: dataraw.encodeABI(),
      to: approveContract,
    };
 
    const result = await approveToken({
      transaction: rawTransaction,
      chain,
    });
 
  } catch (error) {
  // Error Handler
  }
};
 
```

{% endcode %}
{% endtab %}

{% tab title="Demo UI" %}

<figure><img src="/files/m5lKVmyR1oAHIHq2GsEI" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.ramper.xyz/embedded-wallet-sdk/quickstart/for-web-apps/multichain-supported/approve-token.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
