Skip to content

Commit

Permalink
improve doc
Browse files Browse the repository at this point in the history
  • Loading branch information
aliXsed committed May 13, 2024
1 parent 5efaeef commit 97f7115
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions docs/build/sdks/rust/contract-deployment-and-interaction.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,10 +194,10 @@ greeting message:
```

## Advanced Interaction with Smart Contracts Using Rust
In this section, we will explore a more complex scenario involving interactions with a smart contract. We will demonstrate how to read a proposal and check the voting status for a particular address using the zksync-web3-rs and ethers-rs libraries.
In this section, we will explore a more complex scenario involving interactions with a smart contract. We will demonstrate how to read a struct called proposal comprised of multiple fields of different types including different integer types. We also introduce a nested map to record the status of what we call `voting` on `proposal` and demonstrate how you can retrieve its value for a particular address.

### Smart Contract Setup in Solidity
First, let's define the necessary data structures and mappings in your Solidity contract:
First, let's the corresposnding data structures and mappings are defined as follows in your Solidity contract:

```sol
// Defines a proposal specifying payment amount, target address, vote count, and execution status.
Expand All @@ -224,6 +224,7 @@ use ethers::contract::EthAbiType;
use ethers::types::Address;

// Rust representation of the Solidity Proposal struct.
// Note `uint8` type for `votes` is also seen as `Uint` here.
#[derive(Debug, Default, PartialEq, Eq, EthAbiType)]
pub struct Proposal {
target: Address,
Expand All @@ -234,11 +235,12 @@ pub struct Proposal {

// ABI strings for interacting with the contract functions.
pub const CONTRACT_PROPOSALS_CALL: &str = "proposals(bytes32)(address,uint256,uint8,bool)";
// Note how the public getter for a nested map in solidity is constructed below.
pub const CONTRACT_VOTED_CALL: &str = "voted(address,bytes32)(bool)";
```

### Interacting with the Contract
Here is an example of how you can interact with your contract to read a proposal and check the voting status:
### Calling the Contract
Here is an example of how you can read a proposal and check the voting status:

```rust
use ethers::abi::Detokenize;
Expand Down Expand Up @@ -277,7 +279,6 @@ async fn interact_with_contract() {
}
```


[repo]: https://github.com/lambdaclass/zksync-web3-rs/
[code]: https://github.com/lambdaclass/zksync-web3-rs/tree/main/examples/contract-deployment
[test-node]: https://github.com/matter-labs/era-test-node/
Expand Down

0 comments on commit 97f7115

Please sign in to comment.