forked from matter-labs/zksync-era
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
1,494 additions
and
48 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,9 @@ members = [ | |
|
||
# SDK section | ||
"sdk/zksync-rs", | ||
|
||
# Validium Example | ||
"zksync_full_stack", | ||
] | ||
resolver = "2" | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[package] | ||
name = "zksync_full_stack" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | ||
|
||
[dependencies] | ||
zksync-web3-rs = "*" | ||
ethers = "2.0.1" | ||
hex = "0.4.3" | ||
tokio = { version = "1", features = ["macros", "process"] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
[ | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "_greeting", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "nonpayable", | ||
"type": "constructor" | ||
}, | ||
{ | ||
"inputs": [], | ||
"name": "greet", | ||
"outputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "", | ||
"type": "string" | ||
} | ||
], | ||
"stateMutability": "view", | ||
"type": "function" | ||
}, | ||
{ | ||
"inputs": [ | ||
{ | ||
"internalType": "string", | ||
"name": "_greeting", | ||
"type": "string" | ||
} | ||
], | ||
"name": "setGreeting", | ||
"outputs": [], | ||
"stateMutability": "nonpayable", | ||
"type": "function" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0002000000000002000500000000000200010000000103550000006001100270000000830010019d0000008001000039000000400010043f0000000101200190000000a80000c13d0000000001000031000000040110008c000001880000413d0000000101000367000000000101043b000000e001100270000000880210009c000001770000613d000000890110009c000001880000c13d0000000001000416000000000110004c000001880000c13d0000000001000031000000040210008a0000008503000041000000200420008c000000000400001900000000040340190000008502200197000000000520004c000000000300a019000000850220009c00000000020400190000000002036019000000000220004c000001880000c13d00000001020003670000000403200370000000000303043b000000840430009c000001880000213d00000023043000390000008505000041000000000614004b0000000006000019000000000605801900000085011001970000008504400197000000000714004b0000000005008019000000000114013f000000850110009c00000000010600190000000001056019000000000110004c000001880000c13d0000000401300039000000000112034f000000000101043b000000840210009c000001dc0000213d000000bf04100039000000200200008a000000000424016f000000840540009c000001dc0000213d000000400040043f000000800010043f000000240430003900000000034100190000000005000031000000000353004b000001880000213d0000001f0310018f00000001044003670000000505100272000000560000613d00000000060000190000000507600210000000000874034f000000000808043b000000a00770003900000000008704350000000106600039000000000756004b0000004e0000413d000000000630004c000000650000613d0000000505500210000000000454034f0000000303300210000000a005500039000000000605043300000000063601cf000000000636022f000000000404043b0000010003300089000000000434022f00000000033401cf000000000363019f0000000000350435000000a0011000390000000000010435000000800100043d000000840310009c000001dc0000213d000000000400041a000000010340019000000001034002700000007f0530018f00000000030560190000001f0530008c00000000050000190000000105002039000000000454013f0000000104400190000001960000c13d000000200430008c000000870000413d0000001f0410003900000005044002700000008a044000410000008a05000041000000200610008c000000000405401900000000000004350000001f0330003900000005033002700000008a03300041000000000534004b000000870000813d000000000004041b0000000104400039000000000534004b000000830000413d0000001f0310008c000001f30000a13d00000000032101700000008a02000041000000a00400003900000000000004350000009b0000613d00000020060000390000008a020000410000000004000019000000000506001900000080065000390000000006060433000000000062041b000000200650003900000001022000390000002004400039000000000734004b000000910000413d000000a004500039000000000313004b000000a50000813d0000000303100210000000f80330018f000000010500008a000000000335022f000000000353013f0000000004040433000000000334016f000000000032041b00000001020000390000000103100210000001fd0000013d0000000001000416000000000110004c000001880000c13d00000000010000310000001f02100039000000200900008a000000000492016f000000400200043d0000000003240019000000000443004b00000000040000190000000104004039000000840530009c000001dc0000213d0000000104400190000001dc0000c13d000000400030043f0000001f0310018f00000001040003670000000505100272000000c60000613d000000000600001900000005076002100000000008720019000000000774034f000000000707043b00000000007804350000000106600039000000000756004b000000be0000413d000000000630004c000000d50000613d0000000505500210000000000454034f00000000055200190000000303300210000000000605043300000000063601cf000000000636022f000000000404043b0000010003300089000000000434022f00000000033401cf000000000363019f00000000003504350000008503000041000000200410008c000000000400001900000000040340190000008505100197000000000650004c000000000300a019000000850550009c000000000304c019000000000330004c000001880000c13d0000000004020433000000840340009c000001880000213d000000000312001900000000012400190000001f021000390000008504000041000000000532004b0000000005000019000000000504801900000085022001970000008506300197000000000762004b0000000004008019000000000262013f000000850220009c00000000020500190000000002046019000000000220004c000001880000c13d0000000002010433000000840420009c000001dc0000213d0000003f04200039000000000494016f000000400700043d0000000004470019000000000574004b00000000050000190000000105004039000000840640009c000001dc0000213d0000000105500190000001dc0000c13d000000400040043f000000000627043600000000042100190000002004400039000000000334004b000001880000213d000000000320004c000001120000613d000000000300001900000000046300190000002003300039000000000513001900000000050504330000000000540435000000000423004b0000010b0000413d000000000126001900000000000104350000000004070433000000840140009c000001dc0000213d000000000100041a000000010210019000000001011002700000007f0310018f000000000301c0190000001f0130008c00000000010000190000000101002039000000010110018f000000000112004b000001960000c13d000000200130008c000001480000413d000100000003001d000300000004001d000000000000043500000083010000410000000002000414000000830320009c0000000001024019000000c00110021000000086011001c70000801002000039000500000009001d000400000007001d000200000006001d020602010000040f0000000206000029000000040700002900000005090000290000000102200190000001880000613d00000003040000290000001f024000390000000502200270000000200340008c0000000002004019000000000301043b00000001010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b000001480000813d000000000002041b0000000102200039000000000312004b000001440000413d0000001f0140008c000001e20000a13d000300000004001d000000000000043500000083010000410000000002000414000000830320009c0000000001024019000000c00110021000000086011001c70000801002000039000500000009001d000400000007001d020602010000040f000000040600002900000005030000290000000102200190000001880000613d000000030700002900000000033701700000002002000039000000000101043b000001690000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b000001610000413d000000000373004b000001740000813d0000000303700210000000f80330018f000000010400008a000000000334022f000000000343013f00000000026200190000000002020433000000000232016f000000000021041b00000001010000390000000102700210000001ec0000013d0000000001000416000000000110004c000001880000c13d000000040100008a00000000011000310000008502000041000000000310004c000000000300001900000000030240190000008501100197000000000410004c000000000200a019000000850110009c00000000010300190000000001026019000000000110004c0000018a0000613d00000000010000190000020800010430000000000400041a000000010540019000000001014002700000007f0210018f000000000301001900000000030260190000001f0130008c00000000010000190000000101002039000000000114013f00000001011001900000019c0000613d0000008b0100004100000000001004350000002201000039000000040010043f0000008c010000410000020800010430000000400200043d0000000001320436000000000550004c000001ae0000613d0000000000000435000000000430004c0000000004000019000001b40000613d0000008a0500004100000000040000190000000006410019000000000705041a000000000076043500000001055000390000002004400039000000000634004b000001a60000413d000001b40000013d000001000500008a000000000454016f0000000000410435000000000330004c000000200400003900000000040060190000003f03400039000000200400008a000000000543016f0000000003250019000000000553004b00000000050000190000000105004039000000840630009c000001dc0000213d0000000105500190000001dc0000c13d000000400030043f00000020050000390000000005530436000000000202043300000000002504350000004005300039000000000620004c000001cf0000613d000000000600001900000000075600190000000008610019000000000808043300000000008704350000002006600039000000000726004b000001c80000413d000000000152001900000000000104350000005f01200039000000000141016f0000008302000041000000830410009c0000000001028019000000830430009c000000000203401900000040022002100000006001100210000000000121019f000002070001042e0000008b0100004100000000001004350000004101000039000000040010043f0000008c010000410000020800010430000000000140004c0000000001000019000001e60000613d00000000010604330000000302400210000000010300008a000000000223022f000000000232013f000000000221016f0000000101400210000000000112019f000000000010041b0000002001000039000001000010044300000120000004430000008701000041000002070001042e000000000210004c0000000002000019000001f70000613d000000a00200043d0000000303100210000000010400008a000000000334022f000000000343013f000000000332016f0000000102100210000000000123019f000000000010041b0000000001000019000002070001042e00000204002104230000000102000039000000000001042d0000000002000019000000000001042d0000020600000432000002070001042e000002080001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff000000000000000000000000000000000000000000000000ffffffffffffffff80000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000020000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000cfae321700000000000000000000000000000000000000000000000000000000a4136862290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5634e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049640b54fe6c32c3d2b931a12d0e92ca2c903f61744f706361c28dd6cf0a568a |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//SPDX-License-Identifier: Unlicense | ||
pragma solidity ^0.8.8; | ||
|
||
contract Greeter { | ||
string private greeting; | ||
|
||
constructor(string memory _greeting) { | ||
greeting = _greeting; | ||
} | ||
|
||
function greet() public view returns (string memory) { | ||
return greeting; | ||
} | ||
|
||
function setGreeting(string memory _greeting) public { | ||
greeting = _greeting; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
use std::str::FromStr; | ||
|
||
use ethers::{abi::Abi, providers::Http, utils::parse_units}; | ||
use zksync_web3_rs::{ | ||
providers::{Middleware, Provider}, | ||
signers::{LocalWallet, Signer}, | ||
zks_provider::ZKSProvider, | ||
zks_wallet::{CallRequest, DeployRequest, DepositRequest}, | ||
ZKSWallet, | ||
}; | ||
|
||
static ERA_PROVIDER_URL: &str = "http://127.0.0.1:3050"; | ||
static PRIVATE_KEY: &str = "7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"; | ||
|
||
static CONTRACT_BIN: &str = include_str!("../Greeter.bin"); | ||
static CONTRACT_ABI: &str = include_str!("../Greeter.abi"); | ||
|
||
static L1_URL: &str = "http://localhost:8545"; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() { | ||
let l1_provider = | ||
Provider::<Http>::try_from(L1_URL).expect("Could not instantiate L1 Provider"); | ||
let zk_wallet = { | ||
let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap(); | ||
|
||
let chain_id = era_provider.get_chainid().await.unwrap(); | ||
let l2_wallet = LocalWallet::from_str(PRIVATE_KEY) | ||
.unwrap() | ||
.with_chain_id(chain_id.as_u64()); | ||
ZKSWallet::new( | ||
l2_wallet, | ||
None, | ||
Some(era_provider.clone()), | ||
Some(l1_provider.clone()), | ||
) | ||
.unwrap() | ||
}; | ||
|
||
let deposit_transaction_hash = { | ||
let amount = parse_units("11", "ether").unwrap(); | ||
let request = DepositRequest::new(amount.into()); | ||
zk_wallet | ||
.deposit(&request) | ||
.await | ||
.expect("Failed to perform deposit transaction") | ||
}; | ||
|
||
println!("Deposit transaction hash: {:?}", deposit_transaction_hash); | ||
|
||
// Deploy contract: | ||
let contract_address = { | ||
// Read both files from disk: | ||
let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap(); | ||
let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec(); | ||
|
||
// DeployRequest sets the parameters for the constructor call and the deployment transaction. | ||
let request = DeployRequest::with(abi, contract_bin, vec!["Hey".to_owned()]) | ||
.from(zk_wallet.l2_address()); | ||
|
||
// Send the deployment transaction and wait until we receive the contract address. | ||
let address = zk_wallet.deploy(&request).await.unwrap(); | ||
|
||
println!("Contract address: {:#?}", address); | ||
|
||
address | ||
}; | ||
|
||
// Call the greet view method: | ||
{ | ||
let era_provider = zk_wallet.get_era_provider().unwrap(); | ||
let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned()); | ||
|
||
let greet = ZKSProvider::call(era_provider.as_ref(), &call_request) | ||
.await | ||
.unwrap(); | ||
|
||
println!("greet: {}", greet[0]); | ||
} | ||
|
||
// Perform a signed transaction calling the setGreeting method | ||
{ | ||
let receipt = zk_wallet | ||
.get_era_provider() | ||
.unwrap() | ||
.clone() | ||
.send_eip712( | ||
&zk_wallet.l2_wallet, | ||
contract_address, | ||
"setGreeting(string)", | ||
Some(["Hello".into()].into()), | ||
None, | ||
) | ||
.await | ||
.unwrap() | ||
.await | ||
.unwrap() | ||
.unwrap(); | ||
|
||
println!( | ||
"setGreeting transaction hash {:#?}", | ||
receipt.transaction_hash | ||
); | ||
}; | ||
|
||
{ | ||
let era_provider = zk_wallet.get_era_provider().unwrap(); | ||
let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned()); | ||
|
||
let greet = ZKSProvider::call(era_provider.as_ref(), &call_request) | ||
.await | ||
.unwrap(); | ||
|
||
println!("greet: {}", greet[0]); | ||
} | ||
} |