{"id":5683,"library":"poly-eip712-structs","title":"EIP-712 Structs for Python","description":"A Python library providing a robust interface for constructing EIP-712 typed data structures. It simplifies the creation of structured messages that can be signed off-chain and verified on-chain, adhering to the Ethereum EIP-712 standard. The library is currently at version `0.0.1` and aims to streamline secure off-chain data signing.","status":"active","version":"0.0.1","language":"en","source_language":"en","source_url":"https://github.com/Polymarket/poly-py-eip712-structs","tags":["ethereum","eip712","blockchain","cryptography","web3","structs"],"install":[{"cmd":"pip install poly-eip712-structs","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Required for Ethereum utility functions.","package":"eth-utils","optional":false},{"reason":"Required for cryptographic operations.","package":"pycryptodome","optional":false}],"imports":[{"symbol":"EIP712Struct","correct":"from eip712_structs import EIP712Struct"},{"symbol":"make_domain","correct":"from eip712_structs import make_domain"},{"symbol":"String","correct":"from eip712_structs import String"},{"symbol":"Uint","correct":"from eip712_structs import Uint"},{"symbol":"Address","correct":"from eip712_structs import Address"},{"note":"This library is distinct from Python's standard library `struct` module; avoid accidental import collision.","wrong":"from eip712_structs import struct","symbol":"struct","correct":"import struct"}],"quickstart":{"code":"from eip712_structs import make_domain, EIP712Struct, String, Uint\nimport os\n\n# Define a domain separator for the EIP-712 message\ndomain = make_domain(name='My Application', version='1.0.0', chainId=1)\n\n# Define your custom EIP-712 struct type\nclass MyStruct(EIP712Struct):\n    some_string = String()\n    some_number = Uint(256)\n\n# Create an instance of your struct with data\nmy_data = MyStruct(some_string='hello world', some_number=1234)\n\n# Convert to EIP-712 message dictionary\nmessage_dict = my_data.to_message(domain)\nprint(f\"EIP-712 Message Dict: {message_dict}\")\n\n# Get the signable bytes hash (e.g., for use with a private key)\nsignable_bytes = my_data.signable_bytes(domain)\nprint(f\"Signable Bytes Hash: {signable_bytes.hex()}\")\n\n# Example of setting/getting values dictionary-style\nmy_data['some_number'] = 4567\nassert my_data['some_number'] == 4567\n","lang":"python","description":"This quickstart demonstrates how to define an EIP-712 domain, create a custom struct, instantiate it with data, and convert it into a signable EIP-712 message dictionary and its corresponding byte hash."},"warnings":[{"fix":"Always use `from eip712_structs import ...` for imports.","message":"The PyPI package is `poly-eip712-structs`, but the Python import name is `eip712_structs`. Ensure you use `from eip712_structs import ...` in your code.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure only one EIP-712 struct implementation is installed in your environment, or manage import paths carefully if multiple are needed.","message":"Be aware of other packages named `eip712-structs` or `eip712-structs-ng` on PyPI which use the same `eip712_structs` import path. Installing multiple such packages might lead to import conflicts or unexpected behavior.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Always provide at least one parameter when calling `make_domain()`.","message":"The `make_domain()` helper function for creating the EIP-712 domain separator requires at least one parameter (e.g., `name`, `version`, `chainId`) to be defined. Omitting all parameters will result in an invalid domain struct definition.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Use Python 3.9.10 or newer for full compatibility as indicated by PyPI metadata.","message":"The GitHub README states support for Python 3.6 and 3.7. However, the official PyPI metadata specifies `requires_python: >=3.9.10`. Users on older Python versions might encounter installation or runtime issues.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Pin your dependency to a specific `0.0.x` version and review changelogs carefully when upgrading.","message":"As the library is currently at version `0.0.1`, it is in an early development stage. Future updates, especially before a `1.0.0` release, may introduce breaking API changes without strict adherence to semantic versioning for non-major versions.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}