Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
208 changes: 134 additions & 74 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,127 +1,187 @@
# red-py-sdk
# **red-py-sdk**

![](https://img.shields.io/pypi/pyversions/Django.svg)


### install
## **Overview**
`red-py-sdk` is a Python SDK for interacting with the Reddio Layer 2 ecosystem on StarkNet. It allows developers to mint, transfer, withdraw NFTs, and manage balances securely and efficiently.

```
---

## **Installation**

Install the SDK via `pip`:

```bash
pip3 install red-py-sdk
```

### Usage
---

#### Import
## **Quick Start**

```
### **1. Import and Initialize**

Import the SDK and initialize the `Reddio` object. You can use either the **testnet** or **mainnet** environment:

```python
from redpysdk import Reddio
```

#### Init object
Init the object, you can use 'testnet' or 'mainnet' to init the sdk
```
# Initialize on testnet
reddio = Reddio("testnet")
```

#### Get StarkKey Pair
##### Usage
```
get_stark_key_pair()
# Initialize on mainnet
# reddio = Reddio("mainnet")
```
It will generate an random starkkey pair

##### Example
```
>>> reddio.get_stark_key_pair()
('0x395d1708ab0ee91efcb7f26a2f4fcbe20faf3c7390517667fed37b0e481882a', '0x5aa1b67a486b6564a2b6ae7426950c03dfe6991f9d34ea45b6b0be0672a1818')
```
---

#### Mint NFT
##### Usage
```
mintNFT(api_key, contract_address, stark_key, amount)
```
It will mint $amount tokens of $contract_address to $stark_key. first you need to register at dashboard(dashboard.reddio.com) to get your $api_key, and make sure you register the contract_address as ERC721M
### **2. Generate Stark Key Pair**
Generates a random Stark key pair.

##### Example
```
>>> reddio.mintNFT(your_api_key,"0xd60523fd920eb9b7eff3e115203e32d91de5cf59","0x1ccc27877014bc1a81919fc855ebbd1b874603283c9ea93397d970b0704e581","10")
[302808, 302809, 302810, 302811, 302812, 302813, 302814, 302815, 302816, 302817]
**Method**: `get_stark_key_pair()`

**Example**:
```python
stark_pair = reddio.get_stark_key_pair()
print(stark_pair)
```

**Output**:
```plaintext
('0x395d1708ab0ee91efcb7f26a2f4fcbe20faf3c7390517667fed37b0e481882a',
'0x5aa1b67a486b6564a2b6ae7426950c03dfe6991f9d34ea45b6b0be0672a1818')
```

#### Get Balance
---

##### Usage
### **3. Mint NFT**
Mint NFTs to a specified Stark key.

```
get_balances(stark_key, page=1, limit=10)
```
It will return the starkkey's balance. including ERC20/ETH/ERC721
**Method**: `mintNFT(api_key, contract_address, stark_key, amount)`

##### Example
**Parameters**:
- `api_key` *(string)*: Your API key (register at [Reddio Dashboard](https://dashboard.reddio.com)).
- `contract_address` *(string)*: The ERC721M contract address.
- `stark_key` *(string)*: The recipient's Stark key.
- `amount` *(int)*: Number of tokens to mint.

**Example**:
```python
minted_tokens = reddio.mintNFT(
api_key="your_api_key_here",
contract_address="0xd60523fd920eb9b7eff3e115203e32d91de5cf59",
stark_key="0x1ccc27877014bc1a81919fc855ebbd1b874603283c9ea93397d970b0704e581",
amount=10
)
print(minted_tokens)
```
reddio.get_balances("0x6ecaebbe5b9486472d964217e5470380782823bb0d865240ba916d01636310a")

**Output**:
```plaintext
[302808, 302809, 302810, 302811, 302812, 302813, 302814, 302815, 302816, 302817]
```

---

### **4. Get Balances**
Retrieve balances of ETH, ERC20, and ERC721 tokens for a specific Stark key.

**Method**: `get_balances(stark_key, page=1, limit=10)`

#### Transfer
**Parameters**:
- `stark_key` *(string)*: The Stark key to fetch balances for.
- `page` *(int, optional)*: Page number (default = 1).
- `limit` *(int, optional)*: Number of records per page (default = 10).

##### Usage
```
transferNFT(stark_private_key, starkkey, receiver, token_type, contract, tokenID, expiration_timestamp=4194303)
**Example**:
```python
balance = reddio.get_balances(
stark_key="0x6ecaebbe5b9486472d964217e5470380782823bb0d865240ba916d01636310a"
)
print(balance)
```

parameters
- stark_private_key: The private key of layer2
- starkkey: The stark key of layer2
- receiver: The receiver, should be starkkey of other account
- token_type: ERC721 or ERC721M. if mint on layer2 then it should be ERC721M. else it should be ERC721
- tokenID: The token id
- expiration_timestamp: When will it expiration, it is unix timestamp/3600
---

##### Example
### **5. Transfer NFT**
Transfer NFTs between Stark keys.

```
reddio.transferNFT('private_key', '0x6ecaebbe5b9486472d964217e5470380782823bb0d865240ba916d01636310a', '0x1ada455b26b246260b7fd876429289639d7a0ce5fe295ff2355bd4f4da55e2', 'ERC721', '0x941661Bd1134DC7cc3D107BF006B8631F6E65Ad5', '618'))
```
**Method**: `transferNFT(stark_private_key, starkkey, receiver, token_type, contract, tokenID, expiration_timestamp=4194303)`

**Parameters**:
- `stark_private_key` *(string)*: Sender's private key.
- `starkkey` *(string)*: Sender's Stark key.
- `receiver` *(string)*: Recipient's Stark key.
- `token_type` *(string)*: "ERC721" or "ERC721M".
- `contract` *(string)*: The token's contract address.
- `tokenID` *(string)*: The token ID to transfer.
- `expiration_timestamp` *(int, optional)*: Expiry time (default = 4194303).

In the example, you should replace the 'private_key' to the private key of the starkkey
**Example**:
```python
reddio.transferNFT(
stark_private_key="your_private_key_here",
starkkey="0x6ecaebbe5b9486472d964217e5470380782823bb0d865240ba916d01636310a",
receiver="0x1ada455b26b246260b7fd876429289639d7a0ce5fe295ff2355bd4f4da55e2",
token_type="ERC721",
contract="0x941661Bd1134DC7cc3D107BF006B8631F6E65Ad5",
tokenID="618"
)
```

---

### **6. Withdraw NFT**
Withdraw NFTs from Layer 2 back to Layer 1.

**Method**: `withdrawNFT(stark_private_key, starkkey, receiver, token_type, contract, tokenID, expiration_timestamp=4194303)`

#### Withdrawal
**Parameters**:
- `stark_private_key` *(string)*: Sender's private key.
- `starkkey` *(string)*: Sender's Stark key.
- `receiver` *(string)*: Recipient's Stark key.
- `token_type` *(string)*: "ERC721" or "ERC721M".
- `contract` *(string)*: The token's contract address.
- `tokenID` *(string)*: The token ID to withdraw.
- `expiration_timestamp` *(int, optional)*: Expiry time (default = 4194303).

##### Usage
```
withdrawNFT(stark_private_key, starkkey, receiver, token_type, contract, tokenID, expiration_timestamp=4194303)
**Example**:
```python
reddio.withdrawNFT(
stark_private_key="your_private_key_here",
starkkey="0x6ecaebbe5b9486472d964217e5470380782823bb0d865240ba916d01636310a",
receiver="0xffc882996cFAB2C8B9983394E09bb025a98e52bc",
token_type="ERC721",
contract="0x941661Bd1134DC7cc3D107BF006B8631F6E65Ad5",
tokenID="663"
)
```

parameters
- stark_private_key: the private key of layer2
- starkkey: the stark key of layer2
- receiver: the receiver, should be starkkey of other account
- token_type: ERC721 or ERC721M. if mint on layer2 then it should be ERC721M. else it should be ERC721
- tokenID: the token id
- expiration_timestamp: when will it expiration, it is unix timestamp/3600
---

##### Example
### **7. Other Methods**
- **`buy_nft`**: Purchase an NFT on Layer 2.
- **`sell_nft`**: List an NFT for sale on Layer 2.

```
reddio.withdrawNFT('private_key', '0x6ecaebbe5b9486472d964217e5470380782823bb0d865240ba916d01636310a', '0xffc882996cFAB2C8B9983394E09bb025a98e52bc', 'ERC721', '0x941661Bd1134DC7cc3D107BF006B8631F6E65Ad5', '663')
```
*(Detailed documentation for these methods coming soon.)*

---

## **Security Best Practices**
1. **Keep Private Keys Secure**: Store keys securely, e.g., in environment variables or a key vault.
2. **API Key Management**: Avoid hardcoding API keys in source code.
3. **Validate Input**: Ensure parameters such as `contract_address` and `stark_key` are properly formatted.

In the example, you should replace the 'private_key' to the private key of the starkkey
---

## **Contributing**
Contributions are welcome! Submit a pull request or open an issue to help improve the SDK.

#### Others
- buy_nft
- sell_nft
---

## **License**
This project is licensed under the MIT License.



Expand Down