Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Whynot63/abinator
Python data class-like wrapper for solidity abi specification
https://github.com/Whynot63/abinator
Last synced: 3 months ago
JSON representation
Python data class-like wrapper for solidity abi specification
- Host: GitHub
- URL: https://github.com/Whynot63/abinator
- Owner: Whynot63
- License: mit
- Created: 2023-02-26T00:16:47.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-04-04T22:57:52.000Z (over 1 year ago)
- Last Synced: 2024-07-02T06:19:25.213Z (4 months ago)
- Language: Python
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- On-Chain-Investigations-Tools-List - Abinator
README
# 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`.
```python
from abinator import Abi, uint256, uint8class 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.```python
from abinator import Abi, uint256class 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.
```python
from abinator import Abi, Event, address, uint256, indexedclass ERC20Fragment(Abi):
class Transfer(Event):
from_: indexed(address)
to: indexed(address)
value: uint256
```Also there is `anonymous` for event class:
```python
from abinator import Abi, Event, anonymous, uint256class Contract(Abi):
@anonymous
class AnonymousEvent(Event):
value: uint256
```### Structs and tuple
Define structs with child class of `Struct` inside your abi class.```python
from abinator import Abi, Struct, payable, address, uint24, int24, uint256class NonfungiblePositionManager(Abi):
class MintParams(Struct):
token0: address
token1: address
fee: uint24
tickLower: int24
tickUpper: int24
amount0Desired: uint256
amount1Desired: uint256
amount0Min: uint256
amount1Min: uint256
recipient: address
deadline: uint256@payable
def mint(params: MintParams) -> tuple[uint256, uint128, uint256, uint256]:
...
```