A Python API for CafeCosmos
You should have python installed
git clone --recurse-submodules https://github.com/CafeCosmosHQ/cafecosmos-sdk.git
cd cafecosmos-sdk
python3 -m venv .venv
source .venv/bin/activate #(or .venv/bin/activate.fish for fish 🐠)
pip3 install -r requirements.txt
jupyter lab autofarm.ipynb #you could also use the vscode jupyter extensionThe best way to get started is to run that notebook
The Player class provides a robust interface for interacting with the CafeCosmos game environment. It manages the player's resources, inventory, land operations, crafting, and various game-related activities.
def __init__(world: _World, private_key: Optional[str] = None, env_key_name: Optional[str] = None, land_id: Optional[int] = None) -> Noneworld(_World): An instance of theWorldclass that manages game contracts and data.private_key(Optional[str]): The player's private key (default:None).env_key_name(Optional[str]): The environment variable name for the private key (default:None).land_id(Optional[int]): The player's associated land ID (default:None). Automatically selects the first owned land if not provided.
ValueError: If the specifiedland_idis not owned by the player.
def display_land() -> HTMLDisplays the player's land as a grid with visual icons for items.
HTML: The land grid rendered as HTML.
def display_inventory() -> HTMLDisplays the player's inventory with item icons and quantities.
HTML: The inventory table rendered as HTML.
def place_item(x: int, y: int, item_name: str) -> NonePlaces an item on the player's land.
x(int): The x-coordinate for item placement.y(int): The y-coordinate for item placement.item_name(str): The name of the item to place (use"unlock"for unlocking).
def create_land(limit_x: int, limit_y: int) -> NoneCreates a new land for the player.
limit_x(int): The x-dimension size of the land grid.limit_y(int): The y-dimension size of the land grid.
def find_player_lands(amount_of_lands: int = 0) -> List[int]Finds all lands owned by the player.
amount_of_lands(int): Maximum number of lands to find (default:0for unlimited).
List[int]: A list of land IDs owned by the player.
def get_inventory() -> Dict[str, int]Fetches the player's inventory as a dictionary.
Dict[str, int]: A dictionary mapping item names to quantities.
def get_eth_balance() -> intRetrieves the player's ETH balance.
int: The ETH balance in Wei.
def get_leaderboard() -> pd.DataFrameFetches the game's leaderboard.
pd.DataFrame: A DataFrame of leaderboard data.
def transfer_eth(to_address: str, amount: int) -> NoneTransfers ETH to another address.
to_address(str): The recipient's Ethereum address.amount(int): The amount of ETH to transfer in Wei.
def craft_item(item_name: str, quantity: int = 1) -> NoneCrafts an item using the player's inventory.
item_name(str): The name of the item to craft.quantity(int): Number of items to craft (default:1).
def get_craftable() -> pd.DataFrameRetrieves a list of craftable items based on the player's inventory.
pd.DataFrame: A DataFrame of craftable items and their required resources.
def time_until_unlock(x: int, y: int) -> intCalculates the time remaining for an item at (x, y) to unlock.
x(int): The x-coordinate of the item.y(int): The y-coordinate of the item.
int: Time in seconds until the item unlocks (or0if already unlocked).
def get_unlockable_transformations() -> Dict[str, Optional[List[Tuple[int, int]]]]Fetches items on the player's land that can be unlocked.
Dict[str, Optional[List[Tuple[int, int]]]]: A dictionary with unlockable coordinates and the next unlock time.
def unlock_all() -> List[Tuple[int, int]]Unlocks all currently unlockable items on the player's land.
List[Tuple[int, int]]: A list of coordinates for failed unlock attempts.
def auto_farm() -> NoneAutomatically farms resources by unlocking items as they become available.
@staticmethod
def name_to_id_fuzzy(name: str, threshold: int = 80) -> intMatches a fuzzy item name to its ID.
name(str): The item name to match.threshold(int): Fuzzy matching score threshold (default:80).
int: The matching item ID.
@staticmethod
def id_to_name(id: int) -> strMaps an item ID to its name.
id(int): The item ID.
str: The item name.
- Land Display: Renders the player's land with visual icons.
- Inventory Management: Tracks item quantities with graphical outputs.
- Crafting: Automates crafting based on available resources.
- Resource Farming: Unlocks and farms resources in real-time.
- Ethereum Interactions: Supports ETH transfers and balance checks.
For smooth operation, ensure external dependencies such as Items.csv, Web3, and contract ABI files are correctly configured.