> For the complete documentation index, see [llms.txt](https://yuga.gitbook.io/zkyuga-whitepaper/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://yuga.gitbook.io/zkyuga-whitepaper/developer-guide/erc20/approve.md).

# approve

## `approve`

The `approve` function enables token holders to grant permission to another Ethereum address, typically a contract, to spend a specified amount of tokens on their behalf. This operation is frequently utilized in various Ethereum protocols and decentralized applications (dApps), particularly in scenarios where tokens are integrated into other systems like decentralized exchanges or lending platforms. The function is a member of the `ERC20Instance` object, which is obtained through the `getERC20Instance` method of `ZkyugaClient`.

### Method Signature

```javascript
approve(spender: string, amount: BigNumberish, signer: WalletSigner): Promise<TransactionResponse>
```

#### Parameters

| Parameter | Type         | Description                                                                                                                                          |
| --------- | ------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------- |
| spender   | string       | The Ethereum address to which permission is granted to spend the specified amount of tokens on behalf of the owner.                                  |
| amount    | BigNumberish | The maximum number of tokens that the spender can transfer from the owner. This value is specified in the smallest token unit (e.g., Wei for Ether). |
| signer    | WalletSigner | The wallet signer instance responsible for signing the transaction. Typically generated using the `createWalletSigner` method of `ZkyugaClient`.     |

#### Returns

* A `Promise` that resolves to a `TransactionResponse` object, containing transaction details such as its status and hash.

### Usage Example

Start by initializing the desired ERC20 token contract using its contract address:

```javascript
const erc20 = zkyugaClient.getERC20Instance("0x742d35Cc6634C0532925a3b844Bc454e4438f44e");
```

Then, utilize the `approve` function to set an allowance for a specific address:

```javascript
const spenderAddress = "0xa3ACa2a43F8E1C9b7bDBb1908A0cfBF16fE8B3E1";
const approvalAmount = "2000000000000000000"; // This represents 2 tokens, assuming 18 decimals
const signer = zkyugaClient.createWalletSigner("your private key");

const transactionResponse = await erc20.approve(spenderAddress, approvalAmount, signer);
console.log(`Transaction Hash: ${transactionResponse.hash}`);
```

### Considerations

* The `amount` parameter should be specified in the smallest divisible unit of the token. Ensure proper conversions when determining the approval amount.
* Protect your private keys diligently. Handle the `signer` securely and refrain from exposing private keys in insecure or client-side environments.

***
