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.
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.
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.
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.
In Hardhat you use a configuration similar to this one.
Follow these steps to add Rollux Tanenbaum support to an existing Hardhat project (or a newly created one).
d
-
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
-
Add
dotenv
to your project:yarn add dotenv
-
Edit
hardhat.config.js
:-
Use
.env
for your blockchain configuration:require('dotenv').config()
-
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
-
Add a network definition in
module.exports.networks
:
"rollux-tanenbaum": { url: rolluxTanenbaumUrl, chainId: 57000, accounts: { mnemonic: process.env.MNEMONIC } }
-
-
Run the console:
cd hardhat yarn yarn hardhat console --network rollux_tanenbaum
-
Connect to the Greeter contract:
Greeter = await ethers.getContractFactory("Greeter") greeter = await Greeter.attach("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
-
Read information from the contract:
await greeter.greet()
-
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()
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()
In Truffle you use a configuration similar to this one.
Follow these steps to add Rollux Tanenbaum support to an existing Truffle project.
-
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
-
Add
dotenv
and@truffle/hdwallet-provider
to your project:yarn add dotenv @truffle/hdwallet-provider
-
Edit
truffle-config.js
:-
Uncomment this line:
const HDWalletProvider = require('@truffle/hdwallet-provider')
-
Use
.env
for your network configuration:require('dotenv').config()
-
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
-
Add a network definition in
module.exports.networks
:"rollux-tanenbaum": { provider: () => new HDWalletProvider( process.env.MNEMONIC, rolluxTanenbaumUrl), network_id: 57000 }
-
-
Compile the contract and run the console.
truffle compile truffle console --network rollux_tanenbaum
-
Connect to the Greeter contact.
greeter = await Greeter.at("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
-
Read information from the contact.
await greeter.greet()
-
Submit a transaction.
tx = await greeter.setGreeting(`Truffle: Hello ${new Date()}`)
-
Wait a few seconds for the transaction to be processed.s
-
See that the greeting has changed.
greeter.greet()
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()
In Remix you access Rollux through your own wallet.
-
Add Rollux Tanenbaum to your wallet. The easiest way to do this is to use chainlist.org.
-
Log on with your wallet to Rollux Tanenbaum.
-
Browse to Remix.
-
Select the Environment Injected Provider - MetaMask.
-
Accept the connection in the wallet.
-
Make sure your environment is Injected Web3 and the network ID is 57000, reflected by
Custom (57000) network
. -
Download Greeter.sol and upload () it to Remix under contracts.
-
Right-click contracts > Greeter.sol and select Compile.
-
Open contracts > artifacts and see that there's a
Greeter.json
file. This file is the compiled version, the API for the contract, etc. -
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. -
Click greet and expand the transaction result in the console (bottom right).
-
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. -
See the results on the console and then click greet again to see the greeting changed (see it under the greet button).
You deploy a new contract:
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.
-
Set the RPC URL and the contract address.
export ETH_RPC_URL= << Your Rollux Tanenbaum URL goes here >> export GREETER=0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816
-
Call
greet()
. Notice that the response is provided in hex.cast call $GREETER "greet()"
-
Call
greet()
again, and this time translate to ASCIIcast call $GREETER "greet()" | cast --to-ascii
-
Put your mnemonic in a file
mnem.delme
and send a transaction.cast send --mnemonic-path mnem.delme $GREETER "setGreeting(string)" "Foundry hello" --legacy
-
Test that the greeting has changed:
cast call $GREETER "greet()" | cast --to-ascii
Use this command:
forge create --mnemonic-path ./mnem.delme Greeter \
--constructor-args "Greeter from Foundry" --legacy
If you want to develop in Python, you can use the Brownie toolstack.
-
Change to the
brownie
directory undergetting-started
. -
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
-
Install packages.
pip3 install eth-brownie pip3 install dotenv
-
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
-
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
-
Read
.env
import os from dotenv import load_dotenv load_dotenv()
-
Add your accounts to the
accounts
list:from eth_account import Account acct = Account.from_mnemonic(os.getenv("MNEMONIC")) accounts.add(acct.privateKey)
-
Create an object for the contract:
greeter = Greeter.at("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
-
View the current greeting:
greeter.greet()
-
Modify the greeting and see the new one:
greeter.setGreeting("Brownie hello", {'from': accounts[0] }) greeter.greet()
Use this command:
Greeter.deploy("Hello", {'from': accounts[0]})
-
Install Apeworx and create a new project.
pip3 install eth-ape ape init <type project name>
-
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
-
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
-
Edit the configuration file,
ape-config.yaml
:name: greeter default_ecosystem: rollux geth: rollux: tanenbaum: uri: https://rpc-tanenbaum.rollux.com
-
Start the console:
ape console --network rollux:tanenbaum
-
Connect to the Greeter contract:
greeter = project.get_contract("Greeter").at("0x32C00875ca5bc5e6E07A84a39F9fb177d4aeF816")
-
Read information from the contract:
greeter.greet()
-
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.
-
Verify the greeting changed.
greeter.greet()
To deploy a contract from the Apeworx console:
project.get_contract("Greeter").deploy("Hello", sender=acct)
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.
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.