From e32d98a5c9894bc0b3a1831f57615ff25c456bb0 Mon Sep 17 00:00:00 2001 From: glihm Date: Tue, 10 Oct 2023 13:44:16 -0600 Subject: [PATCH] run prettier --- starknet-macros/README.md | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/starknet-macros/README.md b/starknet-macros/README.md index c21e7241..f8d854fc 100644 --- a/starknet-macros/README.md +++ b/starknet-macros/README.md @@ -14,23 +14,27 @@ and all other types found in the `ABI` are generated as `struct` or `enum` as ne work with plain rust types. For instance: + ```rust // Cairo function like fn view_1(self: @ContractState, v: felt252, s: Span) // is generated in rust like: -fn view_1(v: FieldElement, s: Vec); +fn view_1(v: FieldElement, s: Vec); ``` To generate the bindings for your contract, you can do the following: + ```rust use starknet::macros::abigen; abigen!(MyContract, "/path/to/abi.json"); ``` + This will generate all the types and two `struct` for the contract: 1. `MyContractReader`, which is use to call `view` functions that are only reading the blockchain state. To initialize a reader, you need your contract address and a provider: + ```rust let rpc_url = Url::parse("http://0.0.0.0:5050").unwrap(); let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); @@ -39,12 +43,14 @@ This will generate all the types and two `struct` for the contract: let reader = MyContractReader::new(contract_address, &provider); let result = reader.my_view_1().await; ``` + 2. `MyContract`, which in turn is used to call `external` functions, where a transaction is actually sent to the blockchain. This one requires an account, to sign those transactions: + ```rust let rpc_url = Url::parse("http://0.0.0.0:5050").unwrap(); let provider = JsonRpcClient::new(HttpTransport::new(rpc_url.clone())); - + let signer = LocalWallet::from(SigningKey::from_secret_scalar( FieldElement::from_hex_be("").unwrap(), )); @@ -54,7 +60,7 @@ This will generate all the types and two `struct` for the contract: provider.clone(), signer, address, - felt!("0x4b4154414e41"), // KATANA + felt!("0x4b4154414e41"), // KATANA ExecutionEncoding::Legacy, ); @@ -68,6 +74,7 @@ An other feature provided by `abigen` macro is the capabilities of deserialiazin In the `ABI`, there is always an `Event` enum, which contains all the events declared in your contract. You can then do the following: + ```rust let even_page = provider.fetch_events(...); for e in event_page.events {