These examples demonstrate the main features of alloy and alloy-core as well as how to use them.
To run an example, use the command cargo run --example <Example>:
cargo run --example mnemonic_signerExamples that query a live network or fork it with Anvil require you to supply an endpoint:
RPC_URL=https://your-ethereum-endpoint cargo run --example httpWebSocket and IPC examples use WS_URL and IPC_PATH, respectively. Examples with authentication
also list their required credential variables in the error they return.
The fallback-layer example accepts a comma-separated list instead:
RPC_URLS=https://first-endpoint,https://second-endpoint cargo run --example fallback_layerUse an endpoint for the network named by the example. For example, any_network expects an
Arbitrum Sepolia endpoint, while mainnet contract and ENS examples expect Ethereum mainnet.
Examples that fork a network also require anvil in
PATH. Hardware-wallet and cloud-signer examples require the device or credentials described in
their source code.
For programmatic discovery, examples-index.json lists every example with
its summary, source path, exact command, network, environment variables, binaries, services, and
hardware requirements. The index is generated from Cargo metadata and the example source files.
This repository contains the following examples:
- Big numbers
- Comparison
- Contracts
- Deploy from artifact
- Deploy from bytecode
- Deploy from contract
- Deploy and link library
- Interact with ABI
- Interact with contract instance
- Decode custom JSON-RPC errors
- Decode revert data into custom errors
- Handle unknown return types using
DynSol - Simple arbitrage profit calculator for WETH/DAI pools
- Simulate an arbitrage between
Uniswap V2andSushiswap
- ENS
- Fillers (Middleware)
- Layers
- Node Bindings
- Primitives
- Providers
- Queries
-
sol!macro - Subscriptions
- Transactions
- Decode input
- Decode a receipt log
- Encode and decode EIP-1559 transaction
- Get gas price in USD
- Simulate using
debug_traceCallMany - Simulate using
trace_callMany - Trace call
- Trace transaction
- Transfer ERC20 token
- Transfer ERC20 token using a signed permit
- Transfer ETH
- Sign and send a raw transaction
- Send legacy transaction
- Send EIP-1559 transaction
- Send EIP-4844 transaction
- Send EIP-7594 transaction
- Send EIP-7702 transaction
- Send private transaction using Flashbots Protect
- Send transaction with access list
- Wallets
- Advanced
Thanks for your help improving the project! We are so happy to have you! We have a contributing guide to help you get involved in the Alloy project.
Pull requests will not be merged unless CI passes, so please ensure that your contribution follows the linting rules and passes clippy.
Licensed under either of Apache License, Version 2.0 or MIT license at your option.Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in these crates by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.