# Token

In most cases, your code will need to interact with tokens. The SDK makes it easy to find metadata about tokens, including your wallet's balance and current Dexible spend allowance, using the "tokens" sub-component of the SDK instance.

{% hint style="info" %}
It is very important that you perform a lookup on each token you intend to use. The lookup will verify that the token address you're using is valid. After lookup, then you can "verify" the token with Dexible to make sure Dexible will allow you to trade the token.
{% endhint %}

### Looking up Tokens

The following code looks up a token by its address and uses the additional balance and spend allowance information to check errors or increase spending.

{% tabs %}
{% tab title="JavaScript" %}

```javascript
//WETH token metadata
let tokenIn = sdk.token.lookup("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2");
let orderInputAmount = ethers.utils.parseUnits("20", tokenIn.decimals);
if(tokenIn.balance && tokenIn.balance.lt(orderInputAmount)) {
    throw new Error("I don't have enough funds to trade!");
}
if(tokenIn.allowance.lt(orderInputAmount)) {
    await sdk.token.increaseSpending({
        token: tokenIn,
        amount: orderInputAmount.mul(10) //or whatever you want >= orderInputAmount
    });
}
```

{% endtab %}

{% tab title="Python" %}

```python
token_in = asyncio.run(sdk.token.lookup("0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"))
order_input_amount = dexible.common.as_units(20, token_in.decimals)
if token_in.balance < order_input_amount:
    raise Exception("I don't have enough funds to trade!")
if token_in.allowance < order_input_amount:
    asyncio.run(sdk.token.increase_spending(token=token_in, amount=order_input_amount*2))

```

{% endtab %}
{% endtabs %}

### Increase Spending

The example above illustrated how easy it is to increase spending allowance for a token using the SDK. As mentioned earlier, we recommend increasing spending to a level you feel comfortable with but at least enough to cover the cost of the order input amount.

### Verifying Tokens

As mentioned earlier, tokens must pass a verification check before they can be used in an order. The SDK provides a simple way to check whether a token you want to trade is acceptable.&#x20;

{% tabs %}
{% tab title="JavaScript" %}

```javascript
let ok = await sdk.token.verify(tokenIn.address);
if(!ok || ok.error) {
   //cannot trade the token
   throw new Error("Invalid input token");
}
```

{% endtab %}

{% tab title="Python" %}

```python
ok = await sdk.token.verify(token_in.address)
# Use below if not inside a function:
# ok = asyncio.run(sdk.token.verify(token_in.address)
if not ok:
    raise Exception("Invalid input token")
```

{% endtab %}
{% endtabs %}

The verify function will return a boolean or error depending on the result of evaluation. The error may give you clues as to why the token is unacceptable. We debated whether to put the verification directly in the token lookup function; but we decided the two functions have two different objectives: looking up token metadata and verifying that you can use the token for trading.


---

# 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://dexible.gitbook.io/dexible-sdk-v1.0/major-sdk-components/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.
