> 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/stablecoin/approve.md).

# approve

The `approve` method is used to grant permission to a specified user address to spend a certain amount of tokens. This function is part of the StableCoin Contracts, and it plays a critical role in managing token allowances and interactions with other contracts or addresses. The function primarily interfaces with a contract to set the approved amount for the user address.

## Method Signature

```typescript
approve(userAddress: string, amount: string, signer: any): Promise<string>
```

## Parameters

* `userAddress: string`: The Ethereum address of the user to whom the allowance is being given. This can be a regular Ethereum address or an ENS name.
* `amount: string`: The amount of tokens that the user is allowed to spend. This should be specified as a string to avoid precision issues.
* `signer: any`: An object representing the signer of the transaction, typically provided by a wallet interface like MetaMask or ethers.js.

## Function Logic

1. **Resolve ENS Name**: If the `userAddress` provided is an ENS name, it's resolved to its corresponding Ethereum address.
2. **Get Contract Instance**: A contract instance is created using the `signer`, which is necessary to interact with the blockchain.
3. **Approve Transaction**: The `approve` method is called on the contract instance with the resolved `userAddress` and the specified `amount`.
4. **Return Result**: The function returns the result of the `approve` transaction, typically a transaction hash, converted to a string.

## Example Usage

First, instantiate the desired StableCoin token contract using its contract address:

```javascript
const erc20 = zkyugaClient.getStableCoinInstance("0x4DB67190e915C15aA8CCd889F35185D73dA37878");
```

Then, use the `approve` method to set an allowance for a specific address:

```javascript
const userAddress = "example.eth";
const amount = "1000";
const signer = ethersProvider.getSigner();

stableCoinContract.approve(userAddress, amount, signer)
    .then(result => 
        // add your logic here 
    )
    .catch(error => 
        // add your logic here
    );
```

## Notes

* This method is crucial for enabling transactions that involve token allowances, such as staking or spending tokens through a third-party contract.
* It's essential to ensure that the `amount` parameter is correctly formatted to avoid transaction failures or unintended behavior.
