Skip to main content

Setup Solidity ABI

To make your ink! contract compatible with Ethereum tooling, you need to configure it to generate a Solidity-compatible ABI. This allows you to use tools like MetaMask, Hardhat, and Wagmi with your ink! contracts.

Prerequisites

Before starting, ensure you have the latest tools installed:

Latest Tools Required

To ensure compatibility with the latest updates:

  • Install the latest cargo-contract from GitHub:
cargo install --force --tag v6.0.0-alpha.1 --git https://github.com/use-ink/cargo-contract
  • Import ink! from the latest GitHub branch in your Cargo.toml:
ink = { git = "https://github.com/use-ink/ink.git", branch = "6.0.0-alpha.1", default-features = false, features = ["unstable-hostfn"] }

Create and Configure Your Contract

  1. Create a new ink! contract
cargo contract new flipper_evm
cd flipper_evm
  1. Configure Solidity ABI generation in your Cargo.toml. Change:
[package.metadata.ink-lang]
abi = "ink"

to:

[package.metadata.ink-lang]
abi = "sol"

Build with Solidity Metadata

Build your contract with Solidity metadata support:

cargo contract build --release --metadata solidity

This command will generate:

  • The standard ink! contract artifacts
  • A Solidity-compatible ABI file
  • Metadata that can be used with Ethereum tools

Understanding the Output

After building, you'll find additional files in your target/ink/ directory:

  • *.abi - Solidity ABI file compatible with Ethereum tooling for contract interaction.
  • *.json - Contract metadata compatible with Ethereum tooling for reproducible builds and contract verification.

Next Steps

With Solidity ABI configured, you can now: