Skip to content

Latest commit

 

History

History

getting-started

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Getting started developing for Rollux

Discord Twitter Follow

This tutorial teaches you the basics of Rollux development. Rollux is based upon Optimism Bedrock and is EVM equivalent, meaning we run a slightly modified version of the same geth you run on Syscoin mainnet. Therefore, the differences between Rollux development and Syscoin development are minor. But a few differences do exist.

Rollux endpoint URL

To access any Syscoin type network you need an endpoint. RPC and WSS endpoints for Rollux are visible on Chainlist.

Another great option for a Rollux RPC endpoint is Ankr.

Network choice

For development purposes we recommend you use either a local development node or Rollux Tanenbaum. That way you don't need to spend real money. If you need SYS on Rollux Tanenbaum for testing purposes, you can use this faucet.

The tests examples below all use the Rollux Tanenbaum testnet.

Interacting with Rollux contracts

We have Hardhat's Greeter contract on Rollux Tanenbaum, at address 0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816.

You can verify your development stack configuration by interacting with it.

As you can see in the different development stacks below, the way you deploy contracts and interact with them on Rollux is almost identical to the way you do it with L1 Syscoin. The most visible difference is that you have to specify a different endpoint (of course). The list of other differences is here.

Development stacks

Hardhat

In Hardhat you use a configuration similar to this one.

Connecting to Rollux

Follow these steps to add Rollux Tanenbaum support to an existing Hardhat project (or a newly created one).

d

  1. Define your mnemonic in .env:

       MNEMONIC=test test test test test test test test test test trash junk
    
       # API KEY for Ankr.
       ANKR_API_KEY=
    
       # URL to access Rollux Tanenbaum (if not using Ankr)
       ROLLUX_TANENBAUM_URL=https://rpc-tanenbaum.rollux.com
  2. Add dotenv to your project:

    yarn add dotenv
  3. Edit hardhat.config.js:

    1. Use .env for your blockchain configuration:

      require('dotenv').config()
    2. Get the correct URL from the configuration:

         /*This will default to ROLLUX_TANENBAUM_URL if
         you do not specify ANKR_API_KEY in .env */
         const rolluxTanenbaumUrl =
         process.env.ANKR_API_KEY ?
            `https://rpc.ankr.com/rollux_testnet/${process.env.ANKR_API_KEY}` :
            process.env.ROLLUX_TANENBAUM_URL
    3. Add a network definition in module.exports.networks:

    "rollux-tanenbaum": {
       url: rolluxTanenbaumUrl,
       chainId: 57000,
       accounts: { mnemonic: process.env.MNEMONIC }
    }

Greeter interaction

  1. Run the console:

    cd hardhat
    yarn
    yarn hardhat console --network rollux_tanenbaum
  2. Connect to the Greeter contract:

    Greeter = await ethers.getContractFactory("Greeter")
    greeter = await Greeter.attach("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
  3. Read information from the contract:

    await greeter.greet()
  4. Submit a transaction, wait for it to be processed, and see that it affected the state.

    tx = await greeter.setGreeting(`Hardhat: Hello ${new Date()}`)
    rcpt = await tx.wait()
    await greeter.greet()

Deploying a contract

To deploy a contract from the Hardhat console:

Greeter = await ethers.getContractFactory("Greeter")
greeter = await Greeter.deploy("Greeter from hardhat")
console.log(`Contract address: ${greeter.address}`)
await greeter.greet()

Truffle

In Truffle you use a configuration similar to this one.

Connecting to Rollux

Follow these steps to add Rollux Tanenbaum support to an existing Truffle project.

  1. Define your network configuration in .env:

       MNEMONIC=test test test test test test test test test test trash junk
    
       # API KEY for Ankr.
       ANKR_API_KEY=
    
       # URL to access Rollux Tanenbaum (if not using Ankr)
       ROLLUX_TANENBAUM_URL=https://rpc-tanenbaum.rollux.com
  2. Add dotenv and @truffle/hdwallet-provider to your project:

    yarn add dotenv @truffle/hdwallet-provider
  3. Edit truffle-config.js:

    1. Uncomment this line:

      const HDWalletProvider = require('@truffle/hdwallet-provider')
    2. Use .env for your network configuration:

      require('dotenv').config()
    3. Get the correct URL:

         /*This will default to ROLLUX_TANENBAUM_URL if
         you do not specify ANKR_API_KEY in .env */
         const rolluxTanenbaumUrl =
         process.env.ANKR_API_KEY ?
            `https://rpc.ankr.com/rollux_testnet/${process.env.ANKR_API_KEY}` :
            process.env.ROLLUX_TANENBAUM_URL
    4. Add a network definition in module.exports.networks:

      "rollux-tanenbaum": {
         provider: () => new HDWalletProvider(
            process.env.MNEMONIC,
            rolluxTanenbaumUrl),
         network_id: 57000
      }

Greeter interaction

  1. Compile the contract and run the console.

    truffle compile
    truffle console --network rollux_tanenbaum
  2. Connect to the Greeter contact.

    greeter = await Greeter.at("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
  3. Read information from the contact.

    await greeter.greet()
  4. Submit a transaction.

    tx = await greeter.setGreeting(`Truffle: Hello ${new Date()}`)
  5. Wait a few seconds for the transaction to be processed.s

  6. See that the greeting has changed.

    greeter.greet()

Contract deployment

You deploy a new contract from the console.

greeter = await Greeter.new("Greeter from Truffle")

Wait a few seconds for the deployment to actually happen and then verify.

console.log(`Contract address: ${greeter.address}`)
await greeter.greet()

Remix

Connecting to Rollux

In Remix you access Rollux through your own wallet.

  1. Add Rollux Tanenbaum to your wallet. The easiest way to do this is to use chainlist.org.

  2. Log on with your wallet to Rollux Tanenbaum.

  3. Browse to Remix.

  4. Click the run icon ().

  5. Select the Environment Injected Provider - MetaMask.

  6. Accept the connection in the wallet.

Greeter interaction

  1. Click the run icon ().

  2. Make sure your environment is Injected Web3 and the network ID is 57000, reflected by Custom (57000) network.

  3. Click the files icon ().

  4. Download Greeter.sol and upload () it to Remix under contracts.

  5. Right-click contracts > Greeter.sol and select Compile.

  6. Open contracts > artifacts and see that there's a Greeter.json file. This file is the compiled version, the API for the contract, etc.

  7. Click the run icon ().

  8. Scroll down. In the At Address field, type the contract address 0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816. Then, click At Address. Expand the contract to see you can interact with it.

  9. Click greet and expand the transaction result in the console (bottom right).

  10. Type a greeting (preferably, one that starts with the word Remix) and then click setGreeting. Approve the transaction in your wallet. Note that if the greeting includes a comma you need to enclose it in quotes.

  11. See the results on the console and then click greet again to see the greeting changed (see it under the greet button).

Contract deployment

You deploy a new contract:

  1. Type a string for the greeter.

  2. Click Deploy.

  3. Confirm the transaction in the wallet.

Foundry

Greeter interaction

The foundry toolbox includes a set of CLI-based tools for interacting with a project:

  • Forge is a command-line tool that ships with Foundry. Forge tests, builds, and deploys your smart contracts.
  • Cast is Foundry's command-line tool for performing Syscoin RPC calls.
  • Anvil is a local testnet node similar to Ganache.
  • Chisel is an advanced Solidity REPL shipped with Foundry. It can be used to quickly test the behavior of Solidity snippets on a local or forked network.

Foundry does not give us a JavaScript console, everything can be done from the shell command line.

  1. Set the RPC URL and the contract address.

    export ETH_RPC_URL= << Your Rollux Tanenbaum URL goes here >>
    export GREETER=0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816
  2. Call greet(). Notice that the response is provided in hex.

    cast call $GREETER "greet()"
  3. Call greet() again, and this time translate to ASCII

    cast call $GREETER "greet()" | cast --to-ascii
  4. Put your mnemonic in a file mnem.delme and send a transaction.

    cast send --mnemonic-path mnem.delme $GREETER "setGreeting(string)" "Foundry hello" --legacy
  5. Test that the greeting has changed:

    cast call $GREETER "greet()" | cast --to-ascii

Contract deployment

Use this command:

forge create --mnemonic-path ./mnem.delme Greeter \
   --constructor-args "Greeter from Foundry" --legacy

Brownie

If you want to develop in Python, you can use the Brownie toolstack.

Greeter interaction

  1. Change to the brownie directory under getting-started.

  2. Specify your mnemonic in .env:

    # Put the mnemonic for an account on Rollux here
    MNEMONIC=test test test test test test test test test test trash junk
  3. Install packages.

    pip3 install eth-brownie
    pip3 install dotenv
  4. Add the rollux-tanenbaum network.

    brownie networks add Rollux Tanenbaum id=rollux-tanenbaum \
    host=https://rpc-tanenbaum.rollux.com chainid=57000 \
    explorer=https://rollux.tanenbaum.io \
    multicall2=0x1F359C32b5D8c9678b076eAac411A4d2Eb11E697
  5. Start the console.

    brownie console --network rollux_tanenbaum

    Note that the default color scheme assumes a dark background. If your default background is light, you might want to create a file brownie-config.yaml with this content:

    console:
       show_colors: true
       color_style: manni
  6. Read .env

    import os
    from dotenv import load_dotenv
    load_dotenv()
  7. Add your accounts to the accounts list:

    from eth_account import Account
    acct = Account.from_mnemonic(os.getenv("MNEMONIC"))
    accounts.add(acct.privateKey)
  8. Create an object for the contract:

    greeter = Greeter.at("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
  9. View the current greeting:

    greeter.greet()
  10. Modify the greeting and see the new one:

    greeter.setGreeting("Brownie hello", {'from': accounts[0] })
    greeter.greet()

Contract deployment

Use this command:

Greeter.deploy("Hello", {'from': accounts[0]})

Apeworx

Connect to Rollux

  1. Install Apeworx and create a new project.

    pip3 install eth-ape
    ape init
    <type project name>
  2. Install plugins. In this tutorial we use Solidity, but Vyper is also supported by Apeworx.

    Clone the ape-rollux repository and use setuptools for the most up-to-date version:

    git clone https://github.com/bstr156/ape-rollux.git
    cd ape-rollux
    python3 setup.py install
  3. Import your account. Type this command, followed by your mnemonic (the 12 word phrase) and a pass phrase to protect it.

    ape accounts import test --use-mnemonic
  4. Edit the configuration file, ape-config.yaml:

    name: greeter
    
    default_ecosystem: rollux
    
    geth:
    rollux:
          tanenbaum:
             uri: https://rpc-tanenbaum.rollux.com

Greeter interaction

  1. Start the console:

    ape console --network rollux:tanenbaum
  2. Connect to the Greeter contract:

    greeter = project.get_contract("Greeter").at("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
  3. Read information from the contract:

    greeter.greet()
  4. Submit a transaction.

    acct = accounts.load("test")
    greeter.setGreeting("Apeworx says hi ("+acct.address+")", sender=acct)

    Sign the transaction and provide the passphrase if necessary. Ignore error messages if you get them.

  5. Verify the greeting changed.

    greeter.greet()

Deploying a contract

To deploy a contract from the Apeworx console:

project.get_contract("Greeter").deploy("Hello", sender=acct)

Best practices

It is best to start development with the EVM provided by the development stack. Not only is it faster, but such EVMs often have extra features, such as the ability to log messages from Solidity or a graphical user interface.

After you are done with that development, debug your decentralized application using either a development node or the Rollux Tanenbaum test network. This lets you debug parts that are Rollux specific such as calls to bridges to transfer assets between layers.

Only when you have a version that works well on a test network should you deploy to the production network, where every transaction has a cost.

Contract source verification

You don't have to upload your source code to block explorers, but it is a good idea. On the test network it lets you issue queries and transactions from the explorer's user interface. On the production network it lets users know exactly what your contract does, which is conducive to trust.