from dataclasses import dataclass from web3 import Web3 import base64 import json from flask import Flask, jsonify, request app = Flask(__name__) # Web3 connection web3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/YOUR_INFURA_PROJECT_ID')) contract_address = "YOUR_CONTRACT_ADDRESS" contract_abi = 'YOUR_CONTRACT_ABI_JSON_HERE' contract = web3.eth.contract(address=contract_address, abi=contract_abi) @dataclass class LynxAttributes: name: str description: str metadata_uri: str is_blessed: bool is_enchanted: bool is_protected_by_brinks: bool class QuantumLynx: def __init__(self, base_uri): self.base_uri = base_uri self.token_id_counter = 0 self.lynx_attributes = {} def mint_lynx(self, to, name, description, metadata_uri, is_blessed, is_enchanted, is_protected_by_brinks): self.token_id_counter += 1 token_id = self.token_id_counter self.lynx_attributes[token_id] = LynxAttributes( name, description, metadata_uri, is_blessed, is_enchanted, is_protected_by_brinks ) tx_hash = contract.functions.mintLynx( to, name, description, metadata_uri, is_blessed, is_enchanted, is_protected_by_brinks ).transact({'from': web3.eth.defaultAccount}) web3.eth.waitForTransactionReceipt(tx_hash) return f"Lynx NFT minted: {tx_hash.hex()}" def token_uri(self, token_id): assert token_id in self.lynx_attributes, "Token ID does not exist" attributes = self.lynx_attributes[token_id] attributes_dict = { "name": attributes.name, "description": attributes.description, "image": f"{self.base_uri}{token_id}", "attributes": [ {"trait_type": "Blessed by Archangel Michael", "value": "Yes" if attributes.is_blessed else "No"}, {"trait_type": "Enchanted", "value": "Yes" if attributes.is_enchanted else "No"}, {"trait_type": "Protected by BRINKS", "value": "Yes" if attributes.is_protected_by_brinks else "No"} ] } attributes_json = json.dumps(attributes_dict) attributes_base64 = base64.b64encode(attributes_json.encode()).decode() return f"data:application/json;base64,{attributes_base64}" def set_base_uri(self, base_uri): self.base_uri = base_uri @app.route('/mint', methods=['POST']) def mint(): data = request.json response = quantum_lynx.mint_lynx( data['to'], data['name'], data['description'], data['metadata_uri'], data['is_blessed'], data['is_enchanted'], data['is_protected_by_brinks'] ) return jsonify({"message": response}) @app.route('/token_uri/', methods=['GET']) def get_token_uri(token_id): uri = quantum_lynx.token_uri(token_id) return jsonify({"token_uri": uri}) if __name__ == '__main__': quantum_lynx = QuantumLynx("https://baseuri.com/") app.run(host='0.0.0.0', port=5000)