Skip to content

Instantly share code, notes, and snippets.

@glihm
Last active June 8, 2023 14:34
Show Gist options
  • Save glihm/dcb92a18efbefb374b21e28e9144712f to your computer and use it in GitHub Desktop.
Save glihm/dcb92a18efbefb374b21e28e9144712f to your computer and use it in GitHub Desktop.
Sharingan starter pack

Sharingan starter pack

Madara

Madara is a Starknet sequencer. Written using rust and substrate (a SDK to build blockchain), Madara is a community driven sequencer supported by Starkware Keep-Starknet-Strange team which is expected to be one of the major sequencers participating in the Starknet decentralization.

If you don't know Madara, take a look at the repository and the contributor starter pack to have an idea of how it is built.

However, if you just want to participate to Sharingan, you can continue reading this guide, which will guide you without previous Madara knowledge.

What is Sharingan

Sharingan is an ephemeral testnet for Starknet where all nodes participating in the network are Madara instances. In this testnet, Starknet is being tested decentralized, where the nodes work in consensus to determine which block is the next to be added to the chain.

But there are also nodes that are participating in the data storage only, without being involved in the consensus.

Even if Madara is called Starknet Sequencer, we distinguish two types of node in Sharingan:

  1. Madara as a sequencer, participating in the consensus.
  2. Madara as a fullnode, for the data persistence.

For the rest of the guide, sequencer will refer to a Madara instance participating to the consensus, and fullnode to a Madara instance used for data persistence.

The objective of Sharingan is to start testing Starknet being decentralized and also give an access to everybody to participate and test Starknet network.

To interact with the Starknet network, Starknet nodes expose a JSON RPC endpoint. This means that any Madara instance participating in the network will have an open port to allow external communication. More on this in the RPC dedicated section.

If you speak spanish, you surely want to check this version of the guide, made by Nadai for StarknetES community.

Sharingan typology

As mentioned, Sharingan relies on sequencers to produce, validate and add block to the chain. As of today, Sharingan has the following known sequencers:

Maintainer ID Key alias IP Peer ID RPC port
Starkware 1 alice 52.7.206.208 12D3KooWJytWW4wqhG1xp9ckLb7B15KqDU24Q8HHo8VfwXmFe5ZE 9933
Starkware 2 bob 44.195.161.82 12D3KooWHocNfvLz6rgpb8wJsynSpMwkspkcRn6gmN5UiK1tTTeG 9933
Cartridge 3 charlie 208.67.222.222 12D3KooWQe2ZtqiyC5CLJKZr9i9xTmEyiAikZcr5J18w3cG1dQAc 9933
LambdaClass 4 dave 65.109.91.29 12D3KooWK8QhFjkGYGyMskDuCyaS1nrhfTfadMeRjJkox4SV32co 9933
Pragma 5 eve 13.39.22.82 12D3KooWGMCGJ517tFor12U9n2v3ax5WNw1pXFdj48hSHYQe6oyJ 9933
Kakarot 6 ferdie 52.50.242.182 12D3KooWHnQ8LC113DgB5cVVyx2mvTN7bBkm75zvzsndr2WhstEE 9933

More technical details can be found in the discussion here.

As Madara is using substrate, there is an existing web application that allows you to monitor the Sharingan state. And to check the node typology, you can directly go here to the node info tab.

Currently, sequencers are choosen by Starkware, and you can join as a fullnode only.

Participate to Sharingan as a fullnode

To participate to Sharingan, there are few considerations to have in mind:

  1. The Madara code you will be running will need to expose two ports: one for the peer-to-peer communication, which is currently 30333, and one for the RPC mentioned earlier which is usually 9933.

  2. Substrate is using chain specs to have all participating node being in sync on how to collaborate on the network. The chain specification is also special in substrate, as it includes what we call the runtime, where we define how transactions are processed within the nodes.

To participate to Sharingan as a fullnode, you have two options:

Easy way: docker image

There is a docker image built for Sharingan, which will be updated at each version of Sharingan. However, to ensure that you are using the correct chain specs, please proceed to the following:

  1. Download the source code of the current version of Sharingan release (currently v0.1.0-testnet-sharingan-alpha.4).

  2. Extract the archive, to later access the file of interest which is madara/infra/chain-specs/testnet-sharingan-raw.json.

  3. Running the docker container, where we will use 2 volumes. One to access the chain specs file, and another one for the storage of the chain data.

sudo docker run -v /tmp:/data \
                -v /path/to/madara/infra/chain-specs/:/chain-specs \
                ghcr.io/keep-starknet-strange/madara:v0.1.0-testnet-sharingan-alpha.4 \
                --chain /chain-specs/testnet-sharingan-raw.json \
                --base-path /data/sharingan \
                --bootnodes /ip4/52.7.206.208/tcp/30333/p2p/12D3KooWJytWW4wqhG1xp9ckLb7B15KqDU24Q8HHo8VfwXmFe5ZE \
                --rpc-cors=all \
                --rpc-external \
                --rpc-methods=unsafe \
                --port 30333 \
                --rpc-port 9933

Consider running the node in detached mode using the -d option. But try first running without the -d option as it's easier to see what's happening if it's your first time using docker.

Dev way: cloning Madara repository

If you prefer having Madara compiled locally, you must:

  1. Clone Madara repository.
  2. Checkout on the tag v0.1.0-testnet-sharingan-alpha.4.
  3. cargo build --workspace --release (you can check this guide with some info about compiling Madara).
  4. Run the fullnode (in a screen, or any other mean to keep it running) being at the root of Madara repository:
./target/release/madara \
--base-path /path/to/storage/sharingan \
--chain ./infra/chain-specs/testnet-sharingan-raw.json \
--bootnodes /ip4/52.7.206.208/tcp/30333/p2p/12D3KooWJytWW4wqhG1xp9ckLb7B15KqDU24Q8HHo8VfwXmFe5ZE \
--rpc-cors=all --rpc-external --rpc-methods=unsafe \
--port 30333 --rpc-port 9933

Once you have your node running, you can get your Peer ID running the following command:

curl --header "Content-Type: application/json" \
  --request POST \
  --data '{
    "jsonrpc": "2.0",
    "method": "system_localPeerId",
    "params": [],
    "id": 1
}' \
http://your_ip:9933

You can then go to the node explorer and check that your node is appearing and start synchronizing the blocks.

Welcome to Sharingan, you're in! 🚀

For now, there are few transactions, and the storage for the 20,000+ blocks is less that 1GB. But this will vary in the future depending on the network activity.

Interact with Starknet using JSON RPC

To interact with Starknet using a node of Sharingan, you must use JSON RPC directly (with command like curl) or indirectly using Starknet CLI programs like starkli (Some documentation coming soon for starkli).

Currently, Madara is still under active development and it's recommended to regularly check the Starknet features compatibility page of Madara.

In the current version, please don't use unsupported RPC endpoint as we are working on handling them.

Here are some examples of RPC using the sequencer-1 of Starkware:

Get the last block hash:

starkli block-hash --rpc http://52.7.206.208:9933
curl --header "Content-Type: application/json" \
     --request POST \
     --data '{
     "jsonrpc": "2.0",
     "method": "starknet_blockHashAndNumber",
     "params": ["latest"],
     "id":1}' \
     http://52.7.206.208:9933

Sharingan substrate explorer

Here is the web app to visualize Sharingan status.

As mentioned earlier, Madara is using substrate SDK. As a particularity of how Madara uses substrate, any Starknet block is produced and wrapped into a substrate block.

Substrate blocks are not using the same hashing method that Starknet uses. For this reason, the blocks visible in the explorer are not matching the blocks you can see in Starknet explorer like starkscan or voyager.

But this is a great tool to check Sharingan typology and block production.

What can I do on Sharingan

For now, Madara (and then Sharingan) is not supporting Cairo 1, this is coming soon!

The idea is to have lots of people using Sharingan as a testnet, deploying and using contracts sending transactions to Sharingan nodes.

This will be the most effective way to initiate Starknet decentralization.

For now you can take existing Cairo 0 contracts and play with them on Sharingan, but be prepared.. Quantum Leap is coming and Madara is not far behind...! 🚀

Let's continue building and thank you for being part or having interest for Sharingan testnet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment