> For the complete documentation index, see [llms.txt](https://support.marscat.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.marscat.io/development-guide/frontend-development/api-interface/api-interface-details/level-0/connectmarspay.md).

# connectMarsPay

Connect to MarsPay built-in wallet or external wallet for secure interaction between DApp and user wallet. MarsPay wallet supports mainstream EVM blockchains; external wallets support multi-platform access, including WalletConnect and TokenPocket.

{% hint style="success" %}
**Note:**

* Connection is considered complete only after a successful call
* After successful connection, access wallet interfaces via the following global objects:
  * EVM series chains: `window.ethereum = window.parent.top.ethereum`
  * TRON chain: `window.tronWeb = window.parent.top.tronWeb`
* If using TokenPocket on MarsApp, `chainList` must include at least one available chain, otherwise the connection will fail
  {% endhint %}

After successful connection, you can use web3.js and ethers.js to call on-chain contracts without additional configuration.

The following chain list represents the chain types currently supported by MarsPay, with more chains to be added continuously. If the required chain is not yet supported by MarsPay, use external wallet connection.

| Public Chain Name | Abbreviation |
| ----------------- | ------------ |
| Ethereum          | ETH          |
| BNB Chain         | BSC          |
| Polygon           | POLYGON      |
| Avalanche-C       | AVAXC        |
| TRON              | TRON         |
| Arbitrum One      | ARBITRUM     |
| Poly Smart Chain  | PSC          |
| Viction           | VIC          |

Request Parameters:

| Parameter Name | Type  | Required | Description                                                                                                                                                     |
| -------------- | ----- | -------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| chainList      | Array | Yes      | Array of public chain abbreviations to connect (e.g., \["ETH", "BSC"]).                                                                                         |
| walletSupports | Array | No       | Array of supported external wallets (e.g., \["WalletConnect", "TokenPocket"]). If not passed, defaults to connecting MarsPay; passing this adds wallet support. |

Response Parameters:

| Parameter Name | Type   | Description                                                      |
| -------------- | ------ | ---------------------------------------------------------------- |
| chainType      | String | Abbreviation of the chain for the successfully connected wallet. |
| account        | String | Wallet address for the successful connection.                    |

Call Example:

{% code title="connectCocoPay.example.js" %}

```javascript
const payload = {
  chainList: ["ETH", "BSC"],
  walletSupports: ["WalletConnect", "TokenPocket"]
};

const response = await relayx.connectCocoPay(payload);
if (response.code === 200) {
  console.log("Wallet connected:", response.result.account);
} else {
  console.error("Failed to connect wallet");
}
```

{% endcode %}
