|
| 1 | +# Token Example |
| 2 | + |
| 3 | +This example demonstrates how to use the `@crypto.com/developer-platform-client` Token module to interact with blockchain tokens. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Installation](#installation) |
| 8 | +- [Environment Variables](#environment-variables) |
| 9 | +- [Features](#features) |
| 10 | +- [Usage](#usage) |
| 11 | +- [Build](#build) |
| 12 | +- [Development](#development) |
| 13 | +- [License](#license) |
| 14 | + |
| 15 | +## Installation |
| 16 | + |
| 17 | +Navigate to the app folder and install dependencies: |
| 18 | + |
| 19 | +```sh |
| 20 | +cd developer-platform-sdk-examples/sdk-examples/categories/token |
| 21 | +npm install |
| 22 | +``` |
| 23 | + |
| 24 | +## Environment Variables |
| 25 | + |
| 26 | +This example uses a client-side SDK and may require an API key. You can initialize the SDK inside your app code like so: |
| 27 | + |
| 28 | +```ts |
| 29 | +import { Client } from "@crypto.com/developer-platform-client"; |
| 30 | + |
| 31 | +Client.init({ |
| 32 | + apiKey: "sk-proj-...", |
| 33 | +}); |
| 34 | +``` |
| 35 | + |
| 36 | +> **Note:** Never expose real or production API keys in a public or client-side app. |
| 37 | +
|
| 38 | +## Features |
| 39 | + |
| 40 | +## Features |
| 41 | + |
| 42 | +This example showcases the following **Token module** functions: |
| 43 | + |
| 44 | +- **getNativeTokenBalance**: Retrieve the native token balance for a given wallet address (supports `.cro` addresses) |
| 45 | +- **getERC20TokenBalance**: Retrieve the ERC20 token balance for a wallet and contract address |
| 46 | +- **getERC721TokenBalance**: Retrieve the ERC721 token balance for a wallet and contract address |
| 47 | +- **getTokenOwner**: Get the owner of a specific ERC721 token ID |
| 48 | +- **getTokenUri**: Get the token URI for a specific ERC721 token ID |
| 49 | +- **getERC20Metadata**: Fetch metadata (name, symbol, decimals) for an ERC20 token |
| 50 | +- **getERC721Metadata**: Fetch metadata for an ERC721 token contract |
| 51 | +- **transferToken**: Initiate a native or ERC20 token transfer transaction |
| 52 | +- **wrapToken**: Wrap native tokens into wrapped tokens |
| 53 | +- **swapToken**: Swap tokens between ERC20 contracts |
| 54 | + |
| 55 | +## Usage |
| 56 | + |
| 57 | +To run the app in development mode: |
| 58 | + |
| 59 | +```sh |
| 60 | +npm run dev |
| 61 | +``` |
| 62 | + |
| 63 | +Open your browser and navigate to the provided local URL (typically `http://localhost:5173`). |
| 64 | + |
| 65 | +The application provides a user interface to test Token module functions. You can: |
| 66 | + |
| 67 | +- Enter a wallet address to fetch native, ERC20, or ERC721 token balances |
| 68 | +- View token metadata (name, symbol, decimals) for ERC20 and ERC721 contracts |
| 69 | +- Initiate token transfers, swaps, and wraps |
| 70 | +- Fetch ERC721 token owner and token URI information |
| 71 | +- View formatted JSON responses with token data |
| 72 | + |
| 73 | +## Build |
| 74 | + |
| 75 | +To generate a production-ready build: |
| 76 | + |
| 77 | +```sh |
| 78 | +npm run build |
| 79 | +``` |
| 80 | + |
| 81 | +To preview the build: |
| 82 | + |
| 83 | +```sh |
| 84 | +npm run preview |
| 85 | +``` |
| 86 | + |
| 87 | +## Development |
| 88 | + |
| 89 | +- `npm run dev` - Start development server |
| 90 | +- `npm run build` - Build for production |
| 91 | +- `npm run lint` - Run ESLint |
| 92 | +- `npm run preview` - Preview production build |
| 93 | + |
| 94 | +## API Key Requirements |
| 95 | + |
| 96 | +Some functions may require valid API credentials. Make sure to provide valid credentials when testing blockchain transaction features. |
| 97 | + |
| 98 | +## License |
| 99 | + |
| 100 | +This project is licensed under the MIT License. See the LICENSE file for details. |
0 commit comments