Setup the bridge

Guide to initialize your bridge

The front-end application is just a sample, meaning that you can build the front-end in the way you like the most!!

If you are a test net user request the source codes of the bridge and example front-end application by contacting us via email, in the slack channel, or from the contact button in the UI to request a redemption code.

Back-end

Enter the repository.

cd 1DLT bridge

In the truffle-config.js

Inside networks, modify the mnemonic phrase and the address for the 1DLT node and the target chain (e.g., Ropsten).

   networks: {
      ethTestnet: {
      provider: () => new HDWalletProvider(
        private_key, 
        ethereum_rpc,
        0,
        1
      ),
      network_id: 3, //3 is for Ropsten                        
      skipDryRun: true
    },
    qpq: {
      provider: () => new HDWalletProvider(
        private_key, 
        1DLT_rpc
      ),
      network_id: process.env.1DLT_CHAINID,
      skipDryRun: true
    },

Update the .env file.

ETHEREUM_RPC = "websocket Ethereum ropsten endpoint url"
HTTP_ETHEREUM_RPC = "http ropsten endpoint"
SIGNER_PRIVATE_KEY = "your private key"
1DLT_RPC = "your node address"
1DLT_CHAINID = "your node chain id"

Solidity contracts

To deploy the contracts, we rely on Truffle.

Initialize your project:

npm install

Start the migration of the contracts on the two blockchains.

truffle migrate --reset --network ethTestnet
truffle migrate --reset --network qpq

Copy the transaction hash of the generated smart contracts.

Insert the transaction hashed in the public node page.

Press the "add to node" button. This button will trigger the verification, and if successful, the result will look like this:

If you do not want to use the Front-end skip this section and jump to the next one!

Front-end

Enter the repository.

cd 1DLT bridge front-end

Install the dependencies.

npm install

This front end is just an example, which allows you to deposit tokens into 1DLT from a fixed source blockchain (e.g. Ropsten testnet) or withdraw tokens from the same blockchain.

Start the front end.

npm run serve

Get the addresses of the smart contracts.

truffle networks

Result:

To see the token in 1DLT, you have to configure Metamask.

Open Metamask and select the account you want to use.

Then, under the tab "assets", select the "import tokens" button.

Insert the contract address of the target token, the symbol, and the decimals for both the blockchains.

Result:

From the Back-End terminal, start the Bridge API with:

node bridge.js

Result:

In another terminal, start the front-end:

npm run serve

Result:

Select the amount you want to transfer to 1DLT and press the transfer button.

Shortly after, you will see the updated amount in Metamask.

If you want to withdraw, select the amount:

Shortly after, you will see the updated amount in the Metamask

Import an NFT From Ethereum to 1DLT

Below is shown the terminal version for moving an NFT

Before executing the transfer, we check the NFT existence in the two blockchains.

1DLT

truffle exec scripts/erc721-1dlt-token-balance.js --network qpq

Result:

Using network 'qpq'.
0

Ropsten

truffle exec scripts/erc721-eth-token-balance.js --network ethTestnet

Result:

Using network 'ethTestnet'.
1
0x<your-address>

We have no tokens in the account on 1DLT, while we have one token on Ethereum. The owner's address is printed on the terminal and should match your address.

Now, in a new terminal, start the bridge:

node scripts/erc721-eth-1dlt-bridge.js

And in the first terminal, execute the transfer:

truffle exec scripts/erc721-eth-1dlt-transfer.js --network ethTestnet

Result:

Transaction hash: 0x<Hash>

    Processed transfer:
    - to 0x<your-address> 
    - token 9999 // this is the token ID

We check if the token has been transferred from Ethereum to 1DLT:

truffle exec scripts/erc721-eth-token-balance.js --network ethTestnet

Result:

Using network 'ethTestnet'.

0

Then on 1DLT

truffle exec scripts/erc721-1dlt-token-balance.js --network qpq

Result:

Using network 'qpq'.

1
0x<your-address>

Last updated