Skip to content

Commit e287157

Browse files
Contract deployment
Add contract representation to clarity and contract deployment function to web30, along with example use in web30/examples for deploying a compiled contract JSON file.
1 parent 1510e93 commit e287157

10 files changed

Lines changed: 1694 additions & 13 deletions

File tree

README.md

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,75 @@ Our implementation philosophy is that it is up to the developer to understand th
1111

1212
This library is capable of decoding all transactions after Frontier and Homestead hardforks before that some transactions will not pass validation.
1313

14+
## Features
15+
16+
* **Transaction Creation & Signing**: Support for Legacy, EIP-2930, and EIP-1559 transactions
17+
* **ABI Encoding**: Encode function calls and constructor arguments
18+
* **Contract Deployment**: Calculate contract addresses and deploy contracts
19+
* **Address Prediction**: Support for both CREATE and CREATE2 address calculation
20+
* **Transaction Validation**: Comprehensive validation including EIP-3860 init code limits
21+
* **Cross-platform**: Works on any endianness (32/64-bit)
22+
1423
# Web30
1524
[![Latest Version](https://img.shields.io/crates/v/web30.svg)](https://crates.io/crates/web30)
1625
[![Documentation](https://docs.rs/clarity/web30.svg)](https://docs.rs/web30)
1726

1827
Web30 is a equally lightweight rpc client for Ethereum to be paired with Clarity, the goal of this client is to be a minimalist async interface for sending transactions and querying chain state.
1928

29+
## Features
30+
31+
* **Contract Deployment**: High-level API for deploying smart contracts
32+
* **Gas Estimation**: Automatic gas estimation for transactions
33+
* **Transaction Management**: Nonce management and transaction confirmation
34+
* **Web3 RPC**: Essential Ethereum JSON-RPC methods
35+
2036
# Getting Started
2137

22-
See the docs for the API and some usage examples.
38+
## Contract Deployment Example
39+
40+
```rust
41+
use clarity::{PrivateKey, Uint256};
42+
use web30::client::Web3;
43+
use std::time::Duration;
44+
45+
#[tokio::main]
46+
async fn main() {
47+
let web3 = Web3::new("https://eth.llamarpc.com", Duration::from_secs(30));
48+
let private_key: PrivateKey = "0x...".parse().unwrap();
49+
50+
// Contract bytecode from solc
51+
let init_code = hex::decode("608060...").unwrap();
52+
53+
// Deploy contract
54+
let contract_address = web3.deploy_contract(
55+
&private_key,
56+
init_code,
57+
vec![], // Constructor arguments
58+
Uint256::from(0u8), // ETH value
59+
vec![], // Options
60+
).await.unwrap();
61+
62+
println!("Contract deployed at: {}", contract_address);
63+
}
64+
```
65+
66+
## Address Prediction Example
67+
68+
```rust
69+
use clarity::{calculate_contract_address, Address, Uint256};
70+
71+
fn main() {
72+
let deployer: Address = "0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb"
73+
.parse()
74+
.unwrap();
75+
let nonce = Uint256::from(5u8);
76+
77+
let contract_address = calculate_contract_address(deployer, nonce);
78+
println!("Contract will deploy to: {}", contract_address);
79+
}
80+
```
81+
82+
See the `examples/` directory for more detailed examples.
2383

2484
# Ethereum test case status
2585

0 commit comments

Comments
 (0)