For a given ETH wallet:
Transfer a given balance to a new wallet address that belongs to the same holder in a substrate-based parachain.
┌──────────────┐ ┌────────────────────┐
│ │ │ │
│ ETH Wallet │ │ Parachain Wallet │
│ │ │ │
└───────┬──────┘ └───────▲────────────┘
│ │
│ Transfer │ Mint Tokens
┌───────▼──────┐ Req ┌───────────────────────────┐ Mint RPC┌───────┴────────────┐
│ ├───────►│ ├────────►│ │
│ JURBridge.sol│ │ Node.js Relay (Bridge) │ │ JURToken.rs │
│ │◄───────┤ │◄────────┤ │
└──────────────┘ └───────────────────────────┘ ACK └────────────────────┘
Lock Token Register Users
jur-token/
Contains thesolidity
contracts used to represent the original VIP-180 token and the bridge contract that holds funds at the contract address when a transfer is requested.jurbridge/
Holds theink!
contract used to mint new ERC20 compliant tokens on the parachain.relay-server/
Contains thenpm
server used to operate the off-chain relay.
Please make sure you have the following installed:
- ganache
- truffle
- substrate-contracts-node
- Rust tooling
- npm
ganache -m "buffalo learn average iron fly rocket bargain diet fly arrest thank keen"
cd jur-token/
rm -rf build/
truffle compile
truffle migrate
substrate-contracts-node --dev
cd jurbridge
cargo nightly contract build
- Go to the polkadot dashboard
- Upload the contract found at
./jurbridge/target/ink/jurbridge.contract
. - Copy the contract public address to the
PARACHAIN_ADDRESS
variable in./relay-server/-env
.
cd relay-server
npm test
Debugger listening on ws://127.0.0.1:9229/6b458a7f-0c17-469a-85c0-28974e8017ed
For help, see: https://nodejs.org/en/docs/inspector
User register test
✔ tests that a user can successfully register
User already exists test
✔ tests registration should fail if user already exists
ETH to Substrate test
2023-02-04 15:17:24.027 INFO /src/services/ethRelay.ts:70 Getting gas price and nonce
2023-02-04 15:17:24.031 INFO /src/services/ethRelay.ts:74 Sending signed transaction
2023-02-04 15:17:24.047 INFO /src/services/ethRelay.ts:120 Setting approval on token contract
2023-02-04 15:17:24.057 INFO /src/services/ethRelay.ts:137 Locking funds on bridge contract
2023-02-04 15:17:24.069 INFO /src/services/parachainRelay.ts:71 Connecting to substrate endpoint
2023-02-04 15:17:24.111 INFO /src/services/parachainRelay.ts:82 Querying substrate contract for refTime and proofSize
2023-02-04 15:17:24.125 INFO /src/services/parachainRelay.ts:96 Executing transfer to substrate
✔ tests that funds have been successfully transferred from eth to substrate (307ms)
3 passing (341ms)
See relay-server/tests/integration.ts
for example usage
Start the server:
cd relay-server/
npm run start
You can query the relay server using rest endpoints as follows:
curl -XPOST http://localhost:8080/register -d '{"eth":"0x7FB215F9Eb718e0757182Ae9a3A596Bcf0b1c40d", "uri":"//Alice"}' -H "Content-Type: application/json"
curl -XPOST http://localhost:8080/add-funds -d '{"eth":"0x7FB215F9Eb718e0757182Ae9a3A596Bcf0b1c40d", "amount": 10000000}' -H "Content-Type: application/json"
curl -XPOST http://localhost:8080/transfer -d '{"eth":"0x7FB215F9Eb718e0757182Ae9a3A596Bcf0b1c40d", "ethPriv": "0x9fed92bcfe9c078c15d3548e5763c17dde60715ce5fdca5c70f2bfd14b08a4e4", "amount": 1000}' -H "Content-Type: application/json"