Skip to content

Commit

Permalink
Removes message hash from quickstart (#101)
Browse files Browse the repository at this point in the history
# Description

Updates quickstart tutorial to remove message hashing as it adds
unnecessary complexity.
Also updates screenshots.

To be merged with:
zkSync-Community-Hub/zksync-quickstart-remix#1

## Linked Issues

<!-- If you have any issues this PR is related to, link them here. -->
<!--
Check out
https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue
on how to automate linking a GitHub Issue to a PR.
-->

## Additional context
  • Loading branch information
uF4No authored Jun 4, 2024
1 parent 2aada70 commit 1312751
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 11 deletions.
20 changes: 13 additions & 7 deletions content/00.build/05.quick-start/3.deploy-your-first-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ It will help you get familiar with the zkSync smart contract development and dep

In this section you will learn how to:

:check-icon Build a smart contract to exchange secret messages with Zeek.
:check-icon Build a smart contract to exchange messages with Zeek.

:check-icon Deploy the smart contract to the %%zk_testnet_name%%.

Expand All @@ -22,15 +22,15 @@ In this section you will learn how to:

## Review the smart contract code

The smart contract will store messages from users in a hashed format and emit events with replies from Zeek.
The smart contract will store messages from users and emit events with replies from Zeek.
The entire code is as follows:

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
contract ZeekSecretMessages {
bytes32[] private messages;
contract ZeekMessages {
string[] private messages;
// Event to acknowledge a new message
event MessageReceived(string);
Expand All @@ -40,10 +40,8 @@ contract ZeekSecretMessages {
emit MessageReceived("Zeek welcomes you to zkSync!");
}
// Function to send a "secret" message to Zeek
function sendMessage(string memory _message) public {
bytes32 hashedMessage = keccak256(abi.encodePacked(_message));
messages.push(hashedMessage);
messages.push(_message);
// Acknowledge the message receipt with Zeek's reply
emit MessageReceived("ZK is the endgame - Message received!");
Expand All @@ -53,13 +51,21 @@ contract ZeekSecretMessages {
function getTotalMessages() public view returns (uint) {
return messages.length;
}
// Function to return the last message sent to Zeek
function getLastMessage() public view returns (string memory) {
require(messages.length > 0, "No messages sent to Zeek yet!");
return messages[messages.length - 1];
}
}
```

The Solidity smart contract contains two functions:

- `sendMessage` stores the messages sent by users in the `messages` state variable.
- `getTotalMessages` returns the number of messages stored in the smart contract.
- `getLastMessage` returns the last message sent.

::callout{icon="i-heroicons-light-bulb"}
zkSync Era is [EVM compatible](/build/resources/glossary#evm-compatible).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ contract balance and the value returned by the `getTotalMessages` function.
![Contract deployed](/images/101-quickstart/101-atlas-deployed.png)

The “Write Functions” section contains the form to interact with the `sendMessage` function. Write a message, click the
“Run” button and confirm the transaction in your wallet. You’ll see that the `getTotalMessages` is updated to `1`. That
means our contract is storing the messages as expected! But how can you see the replies from Zeek?
“Run” button and confirm the transaction in your wallet. You’ll see that the `getTotalMessages` is updated to `1` and
`getLastMessage` returns the message you just sent. That means our contract is storing the messages as expected! But how
can you see the replies from Zeek?
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ To deploy the contract, open the "Deploy" dropdown, check the "Verify contract"
Verify”. Sign the transaction in your wallet and wait a few seconds until it's processed. Congratulations, you’ve
deployed your first contract to %%zk_testnet_name%%!

![Remix interact zkSync contract](/images/101-quickstart/101-remix-deploy.png)

### Interact with the contract

Next to the contract name you can find the address where the contract is deployed. The “Interact” section displays the
Expand All @@ -46,5 +48,6 @@ forms to interact with the `getTotalMessages` and `sendMessage` functions.
![Remix interact zkSync contract](/images/101-quickstart/101-remix-interact.png)

Write a message in the form, click the “sendMessage” button and confirm the transaction in your wallet. Once processed,
click the `getTotalMessages` and check the response in the terminal, which should be `1`. That means our contract is
storing the messages as expected! But how can we see the replies from Zeek?
click the `getTotalMessages` and check the response in the terminal, which should be `1`. The `getLastMessage` function
should also return the message you just sent. That means the contract is storing the messages as expected! But how can
we see the replies from Zeek?
Binary file modified public/images/101-quickstart/101-atlas-contract.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/101-quickstart/101-atlas-deployed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/101-quickstart/101-contract-deployed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/101-quickstart/101-contract-events.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/images/101-quickstart/101-remix-interact.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 1312751

Please sign in to comment.