Skip to content

Commit

Permalink
initial commit and setup
Browse files Browse the repository at this point in the history
  • Loading branch information
rarcifa committed Oct 16, 2024
1 parent 5916d2f commit 77a7a29
Show file tree
Hide file tree
Showing 20 changed files with 8,817 additions and 1 deletion.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build
/dist


# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
8 changes: 8 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
MIT License

Copyright (c) Crypto.com, https://github.com/crypto-com

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
211 changes: 210 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,210 @@
# developer-platform-client-ts
# Crypto.com Developer Platform Client.ts

The **Crypto.com Developer Platform Client.ts** is a TypeScript/JavaScript SDK designed to interact seamlessly with the Crypto.com Developer Platform Service API. This client library simplifies interactions with the Cronos blockchain, supporting native tokens, ERC20 tokens, smart contracts, transactions, blocks, and wallets.

![npm](https://img.shields.io/npm/v/@crypto.com/developer-platform-client-ts)

## Features

- Simple and intuitive API for interacting with Cronos blockchain networks.
- Supports token balances (native & ERC20), token transfers, wrapping, and swapping.
- Transaction queries by address or hash, and fetching transaction statuses.
- Smart contract ABI fetching by contract address.
- Wallet creation and balance management.
- Supports **Cronos EVM** and **Cronos ZK EVM** chains.

## Installation

To install the package, run the following command in your project directory:

```bash
npm install developer-platform-client-ts
```

## Usage

Here’s how you can use the **Crypto.com Developer Platform Client.ts** in your project:

### Configuring the Client

First, configure the client with your API key and desired blockchain network (Cronos EVM or Cronos ZK EVM):

```ts
import { Client, CronosZkEvm } from "developer-platform-client-ts";

Client.init({
chain: CronosZkEvm.Testnet, // Or CronosEvm.Mainnet for mainnet
apiKey: "YOUR_API_KEY", // Explorer API
provider: "https://provider-url.com", // Optional provider URL for signing
});
```

### Example Operations

#### Wallet Operations

- **Create a Wallet**:

```ts
const wallet = await Wallet.create();
console.log(wallet);
```

- **Get Wallet Balance**:

```ts
const balance = await Wallet.balance("0xYourWalletAddress");
console.log(balance);
```

#### Token Operations

- **Fetch Native Token Balance**:

```ts
const nativeBalance = await Token.getNativeTokenBalance("0xYourWalletAddress");
console.log(nativeBalance);
```

- **Fetch ERC20 Token Balance**:

```ts
const erc20Balance = await Token.getERC20TokenBalance(
"0xYourWalletAddress",
"0xErc20ContractAddress"
);
console.log(erc20Balance);
```

- **Transfer Tokens**:

```ts
const transferResult = await Token.transfer({
to: "0xRecipientAddress",
amount: 10, // Amount of tokens to transfer
});
console.log(transferResult);
```

- **Wrap Tokens**:

```ts
const wrapResult = await Token.wrap({
fromContractAddress: "0xOriginalTokenAddress",
toContractAddress: "0xWrappedTokenAddress",
amount: 10,
});
console.log(wrapResult);
```

- **Swap Tokens**:

```ts
const swapResult = await Token.swap({
fromContractAddress: "0xOriginalTokenAddress",
toContractAddress: "0xSwappedTokenAddress",
amount: 10,
});
console.log(swapResult);
```

#### Transaction Operations

- **Fetch Transactions by Address**:

```ts
const transactions = await Transaction.getTransactionsByAddress(
"0xYourWalletAddress"
);
console.log(transactions);
```

- **Fetch Transaction by Hash**:

```ts
const transaction = await Transaction.getTransactionByHash("0xTransactionHash");
console.log(transaction);
```

- **Get Transaction Status**:

```ts
const status = await Transaction.getTransactionStatus("0xTransactionHash");
console.log(status);
```

#### Contract Operations

- **Fetch Contract ABI by Address**:

```ts
const abi = await Contract.getContractABI("0xContractAddress");
console.log(abi);
```

#### Block Operations

- **Fetch Block by Tag or Block Number**:

```ts
const block = await Block.getBlockByTag("latest"); // Can use 'latest', 'earliest', or a specific block number
console.log(block);
```

## API

### Client Methods

- `Client.init(config)`: Initializes the client with an API key, blockchain network (Cronos EVM or ZK EVM), and an optional provider.
- `Client.getApiKey()`: Returns the configured API key.
- `Client.getProvider()`: Returns the configured provider URL (if available).
- `Client.getChainId()`: Returns the chain ID based on the configured network.

### Wallet Methods

- `Wallet.create()`: Creates a new wallet and returns the address, private key, and mnemonic.
- `Wallet.balance(address)`: Fetches the native token balance for a specified address.

### Token Methods

- `Token.getNativeTokenBalance(address)`: Fetches the native token balance of a wallet address.
- `Token.getERC20TokenBalance(address, contractAddress)`: Fetches the ERC20 token balance of a wallet for a specific contract.
- `Token.transfer(payload)`: Sends a token transfer transaction.
- `Token.wrap(payload)`: Sends a token wrapping transaction.
- `Token.swap(payload)`: Sends a token swapping transaction.

### Transaction Methods

- `Transaction.getTransactionsByAddress(address)`: Fetches transactions associated with a wallet address.
- `Transaction.getTransactionByHash(txHash)`: Fetches transaction details by its hash.
- `Transaction.getTransactionStatus(txHash)`: Fetches the status of a transaction by its hash.

### Contract Methods

- `Contract.getContractABI(contractAddress)`: Fetches the ABI of a smart contract using its contract address.

### Block Methods

- `Block.getBlockByTag(blockTag)`: Fetches block data using a block tag (e.g., 'latest', 'earliest') or block number.

## Supported Chains

The SDK supports both **Cronos EVM** and **Cronos ZK EVM** networks.

### Cronos EVM:

```ts
CronosEvm.Mainnet; // Chain ID: 25
CronosEvm.Testnet; // Chain ID: 338
```

### Cronos ZK EVM:

```ts
CronosZkEvm.Mainnet; // Chain ID: 388
CronosZkEvm.Testnet; // Chain ID: 282
```

## Licensing

The code in this project is licensed under the MIT license.
Loading

0 comments on commit 77a7a29

Please sign in to comment.