Skip to content

Latest commit

 

History

History
91 lines (57 loc) · 3.92 KB

3.setup.and.use.account.cli.md

File metadata and controls

91 lines (57 loc) · 3.92 KB

Setup and Use the account-cli Tool

When working with Nervos' Layer 2 Testnet, there are some tools available that can greatly speed up the development process, and make life easier. One such tool is account-cli. This tool can be used to perform many common Layer 2 actions, such as depositing assets from Layer 1 to Layer 2.

Setup the Godwoken Examples Tool Package

The account-cli tool is part of the Godwoken Examples tool package that is available on GitHub. The first step is to clone the testnet-script branch of this repo, which has been specifically tailored for use with the Gitcoin tasks.

Create ~/projects directory if it doesn't exist.

Linux/MacOS:

mkdir -p ~/projects

Windows (PowerShell):

New-Item -ItemType Directory -Force -Path ~/projects

Enter the ~/projects directory and clone the repository.

cd ~/projects
git clone https://github.com/Kuzirashi/godwoken-examples -b testnet-script

The command above clones the repository and checks out the testnet-script branch which you will be using.

The next step is to configure the tool so it can properly interact with the Testnet. These commands will initialize the tool, then locate the addresses of the Layer 2 resources that are required by the tool and save them to a configuration file.

cd ~/projects/godwoken-examples
yarn
yarn build-all
yarn generate-testnet-configs

Your tools should now be ready to start interacting with Nervos Layer 2!

Note: The 'account-cli' tool is using CKB Node and ckb-indexer. Make sure both tools are synced with Testnet on the first usage.

Polyjuice Address Conversion

We can run a simple test to ensure that account-cli is working properly by doing a Polyjuice address conversion.

A Polyjuice address is the address that Nervos' Layer 2 uses internally to track the Ethereum address behind it. The concept of Polyjuice address exists because of the cross-chain Layer 2 architecture used by Nervos. It is not possible to use the Ethereum address on Nervos Layer 2 because Nervos Layer 2 is designed to also support many other type of blockchain accounts. The addresses from all these different blockchains must be standardized to a single format that Nervos can utilize internally.

Different tools will require different address formats. This tool demonstrates how you can convert between the two.

Convert An Ethereum Address to a Polyjuice Address

You can use the to-short-address command from account-cli to convert from an Ethereum address to a Polyjuice address.

node ./packages/tools/lib/account-cli.js to-short-address -a <YOUR_ETHEREUM_ADDRESS>

Replace <YOUR_ETHEREUM_ADDRESS> with Ethereum address to convert.

As a result of running this command you will receive corresponding Polyjuice address.

Example Output:

➜ node ./packages/tools/lib/account-cli.js to-short-address -a 0xd173313a51f8fc37bcf67569b463abd89d81844f
godwoken short address: 0x8016dcd1af7c8cceda53e4d2d2cd4e2924e245b6

Convert a Polyjuice Address to an Ethereum Address

You can use the to-eth-address command from account-cli to convert from a Polyjuice address to an Ethereum address.

Note: This command will not work until after a Godwoken account has been created on Layer 2 for the corresponding Ethereum address. If you haven't done a deposit yet, skip over this for now.

node ./packages/tools/lib/account-cli.js to-eth-address -a <YOUR_POLYJUICE_ADDRESS>

Replace <YOUR_POLYJUICE_ADDRESS> with Polyjuice address to convert.

As a result of running this command you will receive corresponding Ethereum address.

Example Output:

➜ node ./packages/tools/lib/account-cli.js to-eth-address -a 0x8016dcd1af7c8cceda53e4d2d2cd4e2924e245b6
eth eoa address: 0xd173313a51f8fc37bcf67569b463abd89d81844f