Skip to main content

Python data class-like wrapper for solidity abi specification

Project description

Abinator

Define ABI for your smart contract with dataclass-like style.

Quick example

Define your abi as Abi child. Abi.to_abi() returns abi as json, so you can use it with web3py and web3-premium.

from abinator import Abi, uint256, uint8

class ERC20Fragment(Abi):
    decimals: uint8

    @view
    def balanceOf(account: address) -> uint256:
        ...

ERC20Fragment.to_abi() # returns json with abi

Documentation

State mutability

You can use view, pure, payable decoratos for state mutabilty.

from abinator import Abi, uint256

class Contract(Abi):
    @view
    def balanceOf(account: address) -> uint256:
        ...
    
    @payable
    def deposit():
        ...

    @pure
    def safe_add(a: uint256, b: uint256) -> uint256:
        ...

Events

Define events with child class of Event inside your abi class.

You can use indexed decorator for topics.

from abinator import Abi, Event, address, uint256, indexed

class ERC20Fragment(Abi):
    class Transfer(Event):
        from_: indexed(address)
        to: indexed(address)
        value: uint256

Also there is anonymous for event class:

from abinator import Abi, Event, anonymous, uint256

class Contract(Abi):
    @anonymous
    class AnonymousEvent(Event):
        value: uint256

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

abinator-0.0.1.tar.gz (5.1 kB view hashes)

Uploaded Source

Built Distribution

abinator-0.0.1-py3-none-any.whl (5.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page