@henrlihenrli
Henri
3 years
A first quick disclaimer. Don't expect any kind of reward from the following, except learning some things about StarkNet and trying out a cool new L2. We don't have a token.
@StarkWareLtd
StarkWare 🐺🐱
3 years
Important! StarkWare/StarkNet does not have a token. We will never ask for your private keys. Please beware of scams! ❗️❗️❗️
11
29
307
6
1
76

Replies

@henrlihenrli
Henri
3 years
So, you heard that #StarkNet Alpha is on mainnet (Yes, Ethereum Mainnet) and you want to try it out. Without spending money, preferrably. I got you πŸ˜‰πŸ§Ά
27
186
862
@henrlihenrli
Henri
3 years
So what does it mean for StarkNet to be on Mainnet? - All the logic executed on StarkNet is secured by Ethereum - You can transfer arbitrary messages between both chains - You can use these messages to build bridges (more below)
1
1
60
@henrlihenrli
Henri
3 years
Some cool apps will ship in the coming days that let you test the execution layer on StarkNet. A token bridge will also be there, and let you transmit tokens back and forth Today I want to show you messaging MainNet <-> StarkNet
@shard_labs
Shard Labs
3 years
We are bringing one of the first DAPP on #StarkNet πŸ™Œ πŸš€ πŸš€ Feel free to play around with light version of @ibetyouxyz and share all suggestions with us. 😎 Proud to be part of @StarkWareLtd ecosystem! ✨
5
16
113
1
1
52
@henrlihenrli
Henri
3 years
Why messaging? Because it's a basic building block that allows you to create rich L1 <-> L2 interactions, and because it's tangible. You get to see the results of things you did on SN, on MN.
1
0
30
@henrlihenrli
Henri
3 years
So we're going to write a graffiti on MN. We write a string message on SN, and it appears on MN inside an event. It's simple, and you can play with it through Etherscan and Voyager (SN block explorer).
2
1
27
@henrlihenrli
Henri
3 years
First step is sending the message to StarkNet. The contract is here Notice the "Write contract" tab. You can call paint_graffiti() .
2
0
27
@henrlihenrli
Henri
3 years
SN doesn't handle strings natively yet; you'll need to convert you string to hexadecimal, then decimal. Suboptimal, I know, but we're on the frontier, bear with me. I use this and this
4
0
21
@henrlihenrli
Henri
3 years
Inside the function, it's very simple. Messages to L1 are sent as arrays through send_message_to_l1. The contract stores the L1 recipient address (to_address). So we retrieve to_address from storage; fit your message in an array; send.
Tweet media one
1
0
20
@henrlihenrli
Henri
3 years
Note: transactions are currently free on SN! You don't need to pay for gas. You don't need money to get started. This will change in the future. SN is in Alpha: we are testing a feature set (executing code, MN messages) which will grow
2
0
22
@henrlihenrli
Henri
3 years
You've now sent your message. Cool! Where can you see it? Well, transaction take time to show up in voyager. Like, a very long time (2h). We're working on it and this should change soon. In the meanwhile don't resend. You tx is there. Don't panic
Tweet media one
2
0
15
@henrlihenrli
Henri
3 years
Voyager doesn't show "pending" transactions, only transactions that are in a block. And Starknet on mainnet currently has a block time of 2h. Why? Because there is little trafic for now, and each block cost money. @FeedTheFed can explain better :-)
1
0
15
@henrlihenrli
Henri
3 years
The frequency will increase as trafic increase. Our testnet has a block every 2mn or so . Once your tx is included in a block, you'll see it appear as "accepted on L2".
1
0
13
@henrlihenrli
Henri
3 years
And every ~10h, a "proof" is generated. At that point, the validity of all tx executions on SN is "proved" mathematically to MN, and state is updated accordingly. You can see these updates here
1
0
13
@henrlihenrli
Henri
3 years
That is when your message is transmitted. Going back to the SN smart contract, you can see a "messages" tab. This will list all messages to/from L1, to your contract. If you click on a message, you can see its status
Tweet media one
2
0
10
@henrlihenrli
Henri
3 years
Pending = In a L2 block, waiting for L1 state update Sent = Sent to L1, waiting for L1 counterpart to read it Consumed = Retrieved and interpreted by L1 contract
Tweet media one
2
0
11
@henrlihenrli
Henri
3 years
Interesting detail. Note that your message is sent to L1, but not stored in L1. Only its hash, and the recipient. In order to consume our message, we'll have to re send the message to L1, to recalculate the hash.
Tweet media one
1
0
13
@henrlihenrli
Henri
3 years
Consuming our message means calling consumeMessageFromL2() from a L1 contract. In our case, StarkNetGraffiti has a function graffFromStarknetOnMainnet() that does the trick. StarkNetGraffiti specifies the L2 contract sender address, and the message.
Tweet media one
1
0
11
@henrlihenrli
Henri
3 years
Ok. So at that point, my L1 smart contract can: - Retrieve a message he knows is for it (only it can consume it) - Knows the sender of - Read and use the message And that's your basic building block
1
0
15
@henrlihenrli
Henri
3 years
My message here is a simple int. But consumeMessageFromL2() receives an array. As long as I cast them as uint256, I can pass however many I want. I used my message to emit an event. Mostly because it's the cheapest action I can think of.
1
0
9
@henrlihenrli
Henri
3 years
But I could have - Minted an NFT - Transferred tokens - Deposit on @AaveAave - Swap on @Uniswap - Execute a goverance decision - <insert arbitrary idea you may have>
1
0
18
@henrlihenrli
Henri
3 years
And voila: An event on L1, that was triggered by an action on L2. Nice! Want to try it yourself? The SN contract The L1 contract Sending on L2 is free, consuming on L1 is not. I'll unpack a few messages for you if you ask :-)
2
0
17
@henrlihenrli
Henri
3 years
That's it for now. I hope you learned something :-) Let me know if this is useful, and if you have questions. Repo incoming, needs a bit of cleaning up And soon, we'll go the other way - send a message on L1, graff on L2. Stay tuned 😘
2
0
17
@henrlihenrli
Henri
3 years
Aaaaaand of course I forgot to post the result 😳 There it is
Tweet media one
4
0
25
@henrlihenrli
Henri
3 years
!WARNING! Be careful, there are no safeguards when you send a transaction through Etherscan. This error means your transaction will fail and you'll lose a bunch of ETH. DON'T SEND
Tweet media one
2
0
13
@henrlihenrli
Henri
3 years
Cleaned up the repo a bit; everything is available here
0
2
5