This project is not maintained and has been deprecated in favor of superior designs. If you're interested in these types of things, check out Plasma Group's cutting-edge work on Plasma, Optimistic Rollups, and more!
This is a daemon to relay ERC20 tokens between EVM-based blockchains. The deployer of the smart contracts (TrustedRelay.sol
) is the owner of the contract on the given chain. The contracts are networked together using a config file called networks.json
, which is created when the contracts are deployed. The relayer daemon listens for Deposit
events on every network it knows about (identified by the address of its TrustedRelay contract and connected to via its websocket provider) and uses those to call a relay function on the Gateway contract of the desired destination network.
You will need Truffle, which you can install with npm install -g truffle
.
Two important configuration files are not included with this repo.
NOTE: All chains are identified by chainId
, which can be found with net.version
in your web3 console.
Your networks.json
file is used to identify all of your chains. It should reflect which chains you want to connect
via a relay. This will be generated by default if you run npm run parity <port1> ... <portN>
(See: Testing Daemon with Parity PoA), but if you want to use this with existing chains, you will need to configure this yourself. It is of form:
{
"networks": {
"7545": {
"name": "Origin",
"value": "0x8b45ec0180ee3a2504cf0b2d9696d3ff4ce0c12d",
"gateway": "http://localhost:7545",
"wsProvider": "ws://localhost:7546"
}
}
}
In the above example, I am running a chain which has id (from net.version
) equal to 7545
. This is the index of the first value in the networks
object. The value
is the TrustedRelay contract address. The gateway
is the RPC host. The wsProvider
is the websocket host. The relay daemon requires a websocket host, which is not currently available in TestRPC or Ganache.
NOTE: When running the daemon, it will automatically read from this file and look for the wsGateway
. If you don't have one, it will replace your gateway
with ws
protocol and increment your port by 1.
This networks.json
file is automatically generated when you run truffle migrate
on any given network.
Your secrets.json
must contain a mnemonic
and a hdPath
:
{
"mnemonic": "public okay smoke segment forum front animal extra appear online before various cook test arrow",
"hdPath": "m/44'/60'/0'/0/"
}
You can generate a new BIP39 mnemonic here. Do not change hdPath
unless you have a good reason to - changing it will break the tests.
With your blockchains running and your networks.json
and secrets.json
files set up, you can run your migrations with:
truffle --network <network name> migrate
Make sure to do this for each of the networks you want to connect. Once migrated, you can run the daemon:
npm start
This will log to daemon.log
and daemon.error.log
In order to run the tests, you will need two local blockchains running. Assuming you already have Ganache running on port 7545, you can start a new testrpc instance on port 7546 with (note the raised gas limit):
testrpc -p 7546 -l 6000000 -m "public okay smoke segment forum front animal extra appear online before various cook test arrow"
Note: the mnemonic (-m
) must be the same as the one in your secrets.json
file and it must also be the same one that seeded your Ganache chain (to change, click on the settings gear and go to accounts & keys).
You will also need to have a chain called development
pointed at port 7546 in truffle.js
; this is included by default.
development: {
name: "Dev",
host: 'localhost',
port: 7546,
network_id: '*',
},
You can now run the tests with:
npm run test
NOTE: I recommend upgrading to at least Parity v1.8.4 NOTE: Running this will delete your networks.json file and create a new one. Please back up this file if it's important to you!
If you want to run the relayer daemon, you need to use Parity or Geth, as the daemon uses web3.js 1.0 event pub/sub and websocket listening is not allowed in TestRPC/Ganache. I have included a convenience script to boot one or more parity nodes locally given a series of ports. You can run it with:
npm run parity <port1> <port2> ... <portN>
NOTE: Ports must be 4+ integers apart!
This will fork N child processes as parity proof-of-authority networks using your seed phrase in secrets.json
. The data is in scripts/poa/<port>
.
For convenience, you can create test tokens by calling:
npm run create-token <network> <name> <symbol> <decimals> <supply>
Where <network>
is a key in your networks.json
file. You should only run this script after you have migrated your files on a specified test network.