+
Current value: {value?.toString()}
+
+
+ );
+}
+```
+
+## Solidity Integration
+
+Use exported interfaces in Solidity contracts:
+
+### Import the interface
+
+```solidity
+// SPDX-License-Identifier: MIT
+pragma solidity ^0.8.23;
+
+import "./IMyContract.sol";
+
+contract SolidityContract {
+ IMyContract public stylusContract;
+
+ constructor(address _stylusContract) {
+ stylusContract = IMyContract(_stylusContract);
+ }
+
+ function interactWithStylus() external {
+ // Read from Stylus contract
+ uint256 value = stylusContract.getValue();
+
+ // Write to Stylus contract
+ stylusContract.setValue(value + 1);
+ }
+}
+```
+
+### Cross-language composition
+
+Combine Solidity and Rust contracts:
+
+```solidity
+contract Router {
+ IToken public token;
+ IStaking public staking;
+
+ constructor(address _token, address _staking) {
+ token = IToken(_token); // Rust contract
+ staking = IStaking(_staking); // Rust contract
+ }
+
+ function stakeTokens(uint256 amount) external {
+ // Transfer tokens (Rust contract)
+ require(
+ token.transferFrom(msg.sender, address(this), amount),
+ "Transfer failed"
+ );
+
+ // Stake tokens (Rust contract)
+ token.approve(address(staking), amount);
+ staking.stake(msg.sender, amount);
+ }
+}
+```
+
+## How It Works
+
+### The export-abi feature
+
+The `export-abi` feature enables ABI generation:
+
+```toml
+# Cargo.toml
+[features]
+export-abi = ["stylus-sdk/export-abi"]
+
+[lib]
+crate-type = ["lib", "cdylib"]
+```
+
+When enabled, the SDK generates:
+
+1. A `GenerateAbi` trait implementation
+2. A CLI entry point for running ABI export
+3. Formatting logic for Solidity interface generation
+
+### Main function
+
+Your contract needs a main function for ABI export:
+
+```rust
+// main.rs
+#![cfg_attr(not(any(test, feature = "export-abi")), no_main)]
+
+#[cfg(not(any(test, feature = "export-abi")))]
+#[no_mangle]
+pub extern "C" fn main() {}
+
+#[cfg(feature = "export-abi")]
+fn main() {
+ my_contract::print_from_args();
+}
+```
+
+This main function:
+
+- Runs only when `export-abi` feature is enabled
+- Executes the ABI generation logic
+- Outputs the Solidity interface to stdout
+
+### The #[public] macro
+
+The `#[public]` macro generates ABI code:
+
+```rust
+// From stylus-proc/src/macros/public/export_abi.rs
+impl GenerateAbi for MyContract {
+ const NAME: &'static str = "MyContract";
+
+ fn fmt_abi(f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
+ write!(f, "interface I{} {{", Self::NAME)?;
+ // Generate function signatures
+ write!(f, "\n function getValue() external view returns (uint256);")?;
+ writeln!(f, "}}")?;
+ Ok(())
+ }
+}
+```
+
+Key transformations:
+
+- `snake_case` → `camelCase` function names
+- Rust types → Solidity types
+- `&self` → `view`, `&mut self` → non-view
+- `Result