pub struct ZKSWallet<M, D>{
pub eth_provider: Option<Arc<SignerMiddleware<M, Wallet<D>>>>,
pub era_provider: Option<Arc<SignerMiddleware<M, Wallet<D>>>>,
pub l2_wallet: Wallet<D>,
pub l1_wallet: Wallet<D>,
}Fields§
§eth_provider: Option<Arc<SignerMiddleware<M, Wallet<D>>>>Eth provider
era_provider: Option<Arc<SignerMiddleware<M, Wallet<D>>>>§l2_wallet: Wallet<D>§l1_wallet: Wallet<D>Implementations§
Source§impl<M, D> ZKSWallet<M, D>where
M: Middleware + 'static + Clone,
D: PrehashSigner<(Signature, RecoveryId)> + Sync + Send + Clone,
impl<M, D> ZKSWallet<M, D>where
M: Middleware + 'static + Clone,
D: PrehashSigner<(Signature, RecoveryId)> + Sync + Send + Clone,
Sourcepub fn new(
l2_wallet: Wallet<D>,
l1_wallet: Option<Wallet<D>>,
era_provider: Option<M>,
eth_provider: Option<M>,
) -> Result<Self, ZKSWalletError<M, D>>
pub fn new( l2_wallet: Wallet<D>, l1_wallet: Option<Wallet<D>>, era_provider: Option<M>, eth_provider: Option<M>, ) -> Result<Self, ZKSWalletError<M, D>>
Examples found in repository?
examples/contract-deployment/main.rs (line 29)
19async fn main() {
20 // Note that for this code example we only need to interface with zkSync Era. We don't care
21 // about the Ethereum layer-1 network.
22 let zk_wallet = {
23 let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap();
24
25 let chain_id = era_provider.get_chainid().await.unwrap();
26 let l2_wallet = LocalWallet::from_str(PRIVATE_KEY)
27 .unwrap()
28 .with_chain_id(chain_id.as_u64());
29 ZKSWallet::new(l2_wallet, None, Some(era_provider.clone()), None).unwrap()
30 };
31
32 // Deploy contract:
33 let contract_address = {
34 let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap();
35 let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec();
36 let request = DeployRequest::with(abi, contract_bin, vec!["Hey".to_owned()])
37 .from(zk_wallet.l2_address());
38 let address = zk_wallet.deploy(&request).await.unwrap();
39
40 println!("Contract address: {:#?}", address);
41
42 address
43 };
44
45 // Call the greet view method:
46 {
47 let era_provider = zk_wallet.get_era_provider().unwrap();
48 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
49
50 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
51 .await
52 .unwrap();
53
54 println!("greet: {}", greet[0]);
55 }
56
57 // Perform a signed transaction calling the setGreeting method
58 {
59 let receipt = zk_wallet
60 .get_era_provider()
61 .unwrap()
62 .clone()
63 .send_eip712(
64 &zk_wallet.l2_wallet,
65 contract_address,
66 "setGreeting(string)",
67 Some(["Hello".into()].into()),
68 None,
69 )
70 .await
71 .unwrap()
72 .await
73 .unwrap()
74 .unwrap();
75
76 println!(
77 "setGreeting transaction hash {:#?}",
78 receipt.transaction_hash
79 );
80 };
81
82 // Call the greet view method:
83
84 {
85 let era_provider = zk_wallet.get_era_provider().unwrap();
86 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
87
88 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
89 .await
90 .unwrap();
91
92 println!("greet: {}", greet[0]);
93 }
94}pub fn connect_eth_provider(self, eth_provider: M) -> Self
pub fn connect_era_provider(self, era_provider: M) -> Self
pub fn connect_eth_signer( self, eth_signer: SignerMiddleware<M, Wallet<D>>, ) -> Self
pub fn connect_era_signer( self, era_signer: SignerMiddleware<M, Wallet<D>>, ) -> Self
Sourcepub fn l2_address(&self) -> Address
pub fn l2_address(&self) -> Address
Examples found in repository?
examples/contract-deployment/main.rs (line 37)
19async fn main() {
20 // Note that for this code example we only need to interface with zkSync Era. We don't care
21 // about the Ethereum layer-1 network.
22 let zk_wallet = {
23 let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap();
24
25 let chain_id = era_provider.get_chainid().await.unwrap();
26 let l2_wallet = LocalWallet::from_str(PRIVATE_KEY)
27 .unwrap()
28 .with_chain_id(chain_id.as_u64());
29 ZKSWallet::new(l2_wallet, None, Some(era_provider.clone()), None).unwrap()
30 };
31
32 // Deploy contract:
33 let contract_address = {
34 let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap();
35 let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec();
36 let request = DeployRequest::with(abi, contract_bin, vec!["Hey".to_owned()])
37 .from(zk_wallet.l2_address());
38 let address = zk_wallet.deploy(&request).await.unwrap();
39
40 println!("Contract address: {:#?}", address);
41
42 address
43 };
44
45 // Call the greet view method:
46 {
47 let era_provider = zk_wallet.get_era_provider().unwrap();
48 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
49
50 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
51 .await
52 .unwrap();
53
54 println!("greet: {}", greet[0]);
55 }
56
57 // Perform a signed transaction calling the setGreeting method
58 {
59 let receipt = zk_wallet
60 .get_era_provider()
61 .unwrap()
62 .clone()
63 .send_eip712(
64 &zk_wallet.l2_wallet,
65 contract_address,
66 "setGreeting(string)",
67 Some(["Hello".into()].into()),
68 None,
69 )
70 .await
71 .unwrap()
72 .await
73 .unwrap()
74 .unwrap();
75
76 println!(
77 "setGreeting transaction hash {:#?}",
78 receipt.transaction_hash
79 );
80 };
81
82 // Call the greet view method:
83
84 {
85 let era_provider = zk_wallet.get_era_provider().unwrap();
86 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
87
88 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
89 .await
90 .unwrap();
91
92 println!("greet: {}", greet[0]);
93 }
94}pub fn l1_address(&self) -> Address
pub fn l2_chain_id(&self) -> u64
pub fn l1_chain_id(&self) -> u64
pub fn get_eth_provider( &self, ) -> Result<Arc<SignerMiddleware<M, Wallet<D>>>, ZKSWalletError<M, D>>
Sourcepub fn get_era_provider(
&self,
) -> Result<Arc<SignerMiddleware<M, Wallet<D>>>, ZKSWalletError<M, D>>
pub fn get_era_provider( &self, ) -> Result<Arc<SignerMiddleware<M, Wallet<D>>>, ZKSWalletError<M, D>>
Examples found in repository?
examples/contract-deployment/main.rs (line 47)
19async fn main() {
20 // Note that for this code example we only need to interface with zkSync Era. We don't care
21 // about the Ethereum layer-1 network.
22 let zk_wallet = {
23 let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap();
24
25 let chain_id = era_provider.get_chainid().await.unwrap();
26 let l2_wallet = LocalWallet::from_str(PRIVATE_KEY)
27 .unwrap()
28 .with_chain_id(chain_id.as_u64());
29 ZKSWallet::new(l2_wallet, None, Some(era_provider.clone()), None).unwrap()
30 };
31
32 // Deploy contract:
33 let contract_address = {
34 let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap();
35 let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec();
36 let request = DeployRequest::with(abi, contract_bin, vec!["Hey".to_owned()])
37 .from(zk_wallet.l2_address());
38 let address = zk_wallet.deploy(&request).await.unwrap();
39
40 println!("Contract address: {:#?}", address);
41
42 address
43 };
44
45 // Call the greet view method:
46 {
47 let era_provider = zk_wallet.get_era_provider().unwrap();
48 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
49
50 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
51 .await
52 .unwrap();
53
54 println!("greet: {}", greet[0]);
55 }
56
57 // Perform a signed transaction calling the setGreeting method
58 {
59 let receipt = zk_wallet
60 .get_era_provider()
61 .unwrap()
62 .clone()
63 .send_eip712(
64 &zk_wallet.l2_wallet,
65 contract_address,
66 "setGreeting(string)",
67 Some(["Hello".into()].into()),
68 None,
69 )
70 .await
71 .unwrap()
72 .await
73 .unwrap()
74 .unwrap();
75
76 println!(
77 "setGreeting transaction hash {:#?}",
78 receipt.transaction_hash
79 );
80 };
81
82 // Call the greet view method:
83
84 {
85 let era_provider = zk_wallet.get_era_provider().unwrap();
86 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
87
88 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
89 .await
90 .unwrap();
91
92 println!("greet: {}", greet[0]);
93 }
94}pub async fn eth_balance(&self) -> Result<U256, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn era_balance(&self) -> Result<U256, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn transfer(
&self,
request: &TransferRequest,
_token: Option<Address>,
) -> Result<H256, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn transfer_eip712(
&self,
request: &TransferRequest,
_token: Option<Address>,
) -> Result<H256, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn deposit(
&self,
request: &DepositRequest,
) -> Result<H256, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn deploy_from_bytecode<T>(
&self,
contract_bytecode: &[u8],
contract_dependencies: Option<Vec<Vec<u8>>>,
_constructor_parameters: Option<T>,
) -> Result<H160, ZKSWalletError<M, D>>where
M: ZKSProvider,
T: Tokenizable,
Sourcepub async fn deploy(
&self,
request: &DeployRequest,
) -> Result<H160, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn deploy(
&self,
request: &DeployRequest,
) -> Result<H160, ZKSWalletError<M, D>>where
M: ZKSProvider,
Examples found in repository?
examples/contract-deployment/main.rs (line 38)
19async fn main() {
20 // Note that for this code example we only need to interface with zkSync Era. We don't care
21 // about the Ethereum layer-1 network.
22 let zk_wallet = {
23 let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap();
24
25 let chain_id = era_provider.get_chainid().await.unwrap();
26 let l2_wallet = LocalWallet::from_str(PRIVATE_KEY)
27 .unwrap()
28 .with_chain_id(chain_id.as_u64());
29 ZKSWallet::new(l2_wallet, None, Some(era_provider.clone()), None).unwrap()
30 };
31
32 // Deploy contract:
33 let contract_address = {
34 let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap();
35 let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec();
36 let request = DeployRequest::with(abi, contract_bin, vec!["Hey".to_owned()])
37 .from(zk_wallet.l2_address());
38 let address = zk_wallet.deploy(&request).await.unwrap();
39
40 println!("Contract address: {:#?}", address);
41
42 address
43 };
44
45 // Call the greet view method:
46 {
47 let era_provider = zk_wallet.get_era_provider().unwrap();
48 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
49
50 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
51 .await
52 .unwrap();
53
54 println!("greet: {}", greet[0]);
55 }
56
57 // Perform a signed transaction calling the setGreeting method
58 {
59 let receipt = zk_wallet
60 .get_era_provider()
61 .unwrap()
62 .clone()
63 .send_eip712(
64 &zk_wallet.l2_wallet,
65 contract_address,
66 "setGreeting(string)",
67 Some(["Hello".into()].into()),
68 None,
69 )
70 .await
71 .unwrap()
72 .await
73 .unwrap()
74 .unwrap();
75
76 println!(
77 "setGreeting transaction hash {:#?}",
78 receipt.transaction_hash
79 );
80 };
81
82 // Call the greet view method:
83
84 {
85 let era_provider = zk_wallet.get_era_provider().unwrap();
86 let call_request = CallRequest::new(contract_address, "greet()(string)".to_owned());
87
88 let greet = ZKSProvider::call(era_provider.as_ref(), &call_request)
89 .await
90 .unwrap();
91
92 println!("greet: {}", greet[0]);
93 }
94}pub async fn withdraw(
&self,
request: &WithdrawRequest,
) -> Result<H256, ZKSWalletError<M, D>>where
M: ZKSProvider,
pub async fn finalize_withdraw(
&self,
tx_hash: H256,
) -> Result<H256, ZKSWalletError<M, D>>where
M: ZKSProvider,
Trait Implementations§
Auto Trait Implementations§
impl<M, D> Freeze for ZKSWallet<M, D>where
D: Freeze,
impl<M, D> RefUnwindSafe for ZKSWallet<M, D>where
D: RefUnwindSafe,
M: RefUnwindSafe,
impl<M, D> Send for ZKSWallet<M, D>
impl<M, D> Sync for ZKSWallet<M, D>
impl<M, D> Unpin for ZKSWallet<M, D>where
D: Unpin,
impl<M, D> UnwindSafe for ZKSWallet<M, D>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
Causes
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
Causes
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
Causes
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
Causes
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
Causes
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
Causes
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
Causes
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
Causes
self to use its UpperHex implementation when
Debug-formatted.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Pipes by value. This is generally the method you want to use. Read more
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
Borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
Mutably borrows
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
Borrows
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
Mutably borrows
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
Borrows
self, then passes self.deref() into the pipe function.Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Immutable access to the
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
Mutable access to the
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
Immutable access to the
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
Mutable access to the
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Immutable access to the
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Mutable access to the
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
Calls
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
Calls
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
Calls
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
Calls
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
Calls
.tap_deref() only in debug builds, and is erased in release
builds.