Skip to content

feat(tip20): add scalar view helpers - #75

Open
devorun wants to merge 1 commit into
tempoxyz:mainfrom
devorun:feat/tip20-scalar-read-helpers
Open

feat(tip20): add scalar view helpers#75
devorun wants to merge 1 commit into
tempoxyz:mainfrom
devorun:feat/tip20-scalar-read-helpers

Conversation

@devorun

@devorun devorun commented Aug 11, 2026

Copy link
Copy Markdown

Summary

TIP20 already exposes typed role query helpers (has_role, get_role_admin, the role constants) and typed write builders for the full token interface, but it has no helpers for the standard scalar reads — callers have to drop down to w3.eth.contract(TIP20_ABI) just to read a balance.

This adds six scalar view helpers to TIP20, following the existing role-query pattern (encode calldata from the shipped ABI → eth_call → decode a single word):

  • balance_of(w3, *, account)balanceOf(address)
  • allowance(w3, *, owner, spender)allowance(address,address)
  • total_supply(w3)totalSupply()
  • decimals(w3)decimals()
  • supply_cap(w3)supplyCap() (complements the existing set_supply_cap)
  • paused(w3)paused() (complements the existing pause / unpause)

All decode via the existing _decode helpers (decode_uint / decode_bool); no new decoding machinery is introduced. String views (name / symbol) are intentionally left out as they require dynamic ABI decoding.

Tests

Unit tests cover selector encoding, result decoding, empty-address rejection, and non-canonical bool rejection.

Changelog

Includes a pytempo: minor changelog fragment.

Expose balanceOf, allowance, totalSupply, decimals, supplyCap, and paused
as typed read helpers on TIP20, mirroring the existing role query helpers.
Each returns a decoded Python value from a single eth_call.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant