---
# System prepended metadata

title: How to decode Mantapay's Event

---

## Archival Nodes

| Endpoint | Country | 
| -------- | -------- |
| wss://a1.calamari.systems     | UK     |
| wss://a2.calamari.systems     | US     |
| wss://avocado.calamari.systems     | UK     |
| wss://fritti.calamari.systems     | Japan     |

## The block includes 1st private tx
Block number:
```
https://calamari.subscan.io/block/3190993
```
Basically, you can start to scan blocks from `3190993 `.

## Tokens


| Token Name | Asset Id | Decimal |
| -------- | -------- | -------- |
| KMA     | 1     | 12     |
| KAR     | 8     | 12     |
| MOVR     | 11     | 18     |
| KSM     | 12     | 12     |
| USDT     | 14     | 6     |
| USDC     | 16     | 6     |
| DAI     | 15     | 18     |

## How to decode

### The metadata from mantapay
- Module name
```
mantaPay
```
- Event name

    - `ToPrivate`: public token to private token
    Two fields in this event:
        - `asset`: contains asset id, how many token will be `ToPrivate`ed.
        - `source`: signer
    
        If `ToPrivate` is detected, you can decode it in this way.
        ```ts
        const [asset, signer] = event.data;
        const assetId = decodeAssetId(asset.toJSON().valueOf()['id']);
        const amount = toUnit(decodeAssetValue(asset.toJSON().valueOf()['value']), assetId).toNumber();
        ```
    - `PrivateTransfer`: private token to private token, 
    Only one field in this event, no one knows how many tokens is transfered:
        - `origin`: signer
    
        If `PrivateTransfer` is detected, you can decode it in this way.
        ```ts
        const [signer] = event.data;
        ```
    - `ToPublic`: private token to public token
    Two fields in this event:
        - `asset`: contains asset id, how many token will be `ToPublic`ed.
        - `sink`: signer
    
        If `ToPublic` is detected, you can decode it in this way.
        ```ts
        const [asset, signer] = event.data;
        const assetId = decodeAssetId(asset.toJSON().valueOf()['id']);
        const amount = toUnit(decodeAssetValue(asset.toJSON().valueOf()['value']), assetId).toNumber();
        ```

- Utility Functions
```ts
function decodeAssetValue(hexString: string) {
  const array = hexToU8a(hexString);
  const value = u8aToBn(array);
  return value;
}

function toUnit(balance: BN, assetId: number) {
  const decimal = todo!(); // get decimal by asset id.
  const b = new BigNumber(decimal.toString());
  const c = a.div(b);
  return c;
}

function decodeAssetId(assetId: string) {
  const array = hexToU8a(assetId);
  const value = u8aToBn(array);
  return value.toNumber();
}
```
