1. Define Interface
Create a Java interface that mirrors your Solidity contract.2. Bind Contract
UseBraneContract.bind to create an instance of your interface.
3. Interact
Call methods directly on the interface.Validation
When you callBraneContract.bind, the SDK performs strict validation to ensure your Java interface matches the contract ABI. This “fail-fast” behavior prevents runtime errors.
The validation checks:
- Method Existence: Every method in your interface must exist in the ABI.
- Parameter Count: The number of arguments must match.
- Type Compatibility: Java types must be compatible with Solidity types (e.g.,
uint256->BigInteger). - Mutability: You cannot bind a
voidreturn type to aviewfunction (it must return a value).
bind throws an IllegalArgumentException with a detailed error message explaining the mismatch.
Supported Types
The binding system automatically maps Solidity types to Java types:| Solidity | Java |
|---|---|
uint256, int256 | java.math.BigInteger |
address | io.brane.core.types.Address |
bool | java.lang.Boolean |
string | java.lang.String |
bytes | io.brane.core.types.HexData |
uint8…uint64 | java.math.BigInteger |