Skip to content

Conversation

@pgherveou
Copy link
Collaborator

Summary

  • Add pvm-contract-macros crate with proc macros for contract development
  • Add pvm_contract runtime library crate
  • Add ABI generation to the builder (outputs .abi.json alongside .polkavm)
  • Make Solidity interface files optional - signatures can be inferred from Rust types

New Crates

pvm-contract-macros

Proc macros for defining PolkaVM contracts:

  • #[pvm_contract::contract] - Define a contract module
  • #[pvm_contract::method] - Mark functions as contract methods (automatic selector generation)
  • #[pvm_contract::constructor] - Mark constructor function
  • #[pvm_contract::fallback] - Mark fallback function

pvm_contract

Runtime library re-exporting the macros and types.

Key Features

Simplified Method Attributes

Before: #[pvm_contract::method("transfer(address,uint256)")]
After: #[pvm_contract::method] (signature inferred from Rust types)

Optional rename: #[pvm_contract::method(rename = "getBalance")]

Automatic Type Mapping (Rust → Solidity)

Rust Type Solidity Type
Address address
U256 uint256
u128 uint128
u64 uint64
u32 uint32
bool bool
[u8; 32] bytes32

ABI Generation

The builder now parses contract source files and generates ABI JSON files alongside the compiled .polkavm binaries.

Testing

  • All existing tests pass
  • Doctests added for macro usage examples

- Add pvm-contract-macros crate with proc macros for contract development
- Add pvm_contract runtime crate with re-exports and helpers
- Add ABI generation to cargo-pvm-contract-builder
  - Parses Rust contracts to extract method signatures
  - Supports both sol file and Rust type inference
  - Outputs .abi.json alongside .polkavm binary
- Sol file is now optional in #[pvm_contract::contract]
- Method signatures can be inferred from Rust types
- Add rename attribute for custom Solidity function names
- Comprehensive rustdoc documentation
@pgherveou pgherveou marked this pull request as draft January 23, 2026 17:35
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.

2 participants