> For the complete documentation index, see [llms.txt](https://pet-poodl.gitbook.io/pet-for-developers/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://pet-poodl.gitbook.io/pet-for-developers/whitelabel/page-3.md).

# Events

Events are available as callback functions in the PoodlApp config object. Each event will provide you with a set of outputs that can then be used in custom functions.

{% hint style="info" %}
Note that events are fired locally, async functions are therefore not required.
{% endhint %}

## onAccountChange

This event is triggered every time users connect or disconnect their wallet as well as switching between accounts.

<pre class="language-typescript"><code class="lang-typescript">/*
* available args
* newAccount: string
* oldAccount: string
*/
<strong>onAccountChange: newAccount => {
</strong><strong>    console.log(newAccount)
</strong><strong>}
</strong></code></pre>

## onChainChange

This event is triggered every time users change newtork (chain).

<pre class="language-typescript"><code class="lang-typescript">/*
* available args
* newChainId: chainId
* oldChainId: chainId
*/
onChainChange: newChainId => {
<strong>    console.log(newChainId)
</strong><strong>}
</strong></code></pre>

## onTokenSelect

This event is triggered every time users change either the input or the output token.

It gives back 2 json objects - `inputToken` and `outputToken`

```typescript
/*
* available args
* inputToken: Token
* outputToken: Token
*/
inputToken : {
    address: string,
    chainId: number,
    decimals: number,
    hasTransactonFees: boolean,
    logoURI: string,
    name: string,
    symbol: string
}
outputToken : {
    address: string,
    chainId: number,
    decimals: number,
    hasTransactonFees: boolean,
    logoURI: string,
    name: string,
    symbol: string
}
```

Usage example:

<pre class="language-typescript"><code class="lang-typescript"><strong>onTokenSelect: inputToken => {
</strong><strong>    console.log(inputToken.chainId)
</strong><strong>    console.log(inputToken.decimals)
</strong><strong>}
</strong></code></pre>

## onSuccessSwap

This event is triggered every time users succesfully swap a token through the widget

It gives back a json object - `quote`

The quote object represent the aggregator quote used to submit the transaction and therefore it includes all the information related to that transaction.

```typescript
/*
* available args
* quote: aggregatorQuote
*/

quote : {
    from: string, //address of the user
    chainId: number, // chain where the transaction took place
    buyTokenAddress: string, // address of the token to be bought
    sellTokenAddress: string, // address of the token to be sold
    sellAmount: number, // amount sold
    buyAmount: string, // amount bought
}
```

This is particularly useful for tracking or analytics purposes:

<pre class="language-typescript"><code class="lang-typescript">// Database
<strong>onSuccessSwap: quote => {
</strong><strong>    //{code to push to database(quote)}
</strong><strong>}
</strong>
<strong>// Google analytics
</strong><strong>// {define Google analytics event}
</strong>onSuccessSwap: quote => {
    //{Google analytics event(quote)}
}
</code></pre>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://pet-poodl.gitbook.io/pet-for-developers/whitelabel/page-3.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
