Skip to content

Latest commit

 

History

History
78 lines (59 loc) · 5.92 KB

4.layer2.deposit.md

File metadata and controls

78 lines (59 loc) · 5.92 KB

Create a Godwoken Account by Making a Layer 2 Deposit

Before a user can start using Godwoken, they first need to create an account. Creating an account on Layer 2 begins with the first logical step, depositing funds from Layer 1 to Layer 2. This single action creates the account and funds it so it is ready to be used.

1. Setup the Godwoken Examples Tool Package

The first step is to setup the Godwoken Examples tool package. This is a collection of scripts that has been created to help with commonly needed actions when dealing with Layer 2. These actions include the deposit and withdrawl of CKBytes and SUDT tokens to and from Layer 2.

To setup the Godwoken Examples tool package, follow the this tutorial.

2. Make a Deposit to Layer 2

The next step is to deposit some CKBytes from Layer 1 to Layer 2. To do this we need the private key of your Layer 1 account, and we also need to know what your Ethereum address is so we can depost to it on Layer 2.

First, we need to find the private key that was generated for your Layer 1 account. It should look something like this:

0x79682c20bbcaf7fcf18eb0c69b133c872227ceb88971090e7f2242c80cd54d18

Note: The above line is our demonstration private key. You need to use the private key you generated earlier. Do not use any other value except the private key. If you are unsure what the private key is, go back to task 1 and complete the steps to export your private key.

Next, we need to locate your Ethereum address. You can find this by opening MetaMask and clicking on the address field to copy it.

Then we use the account-cli tool to make the deposit by providing your private key, and the Ethereum address you are depositing to:

node ./packages/tools/lib/account-cli.js deposit -p <YOUR_PRIVATE_KEY> -l <YOUR_ETH_ADDRESS> -c <SHANNONS_AMOUNT> -r <INSERT_TESTNET_RPC_URL> -i <INSERT_TESTNET_INDEXER_URL>
  1. <YOUR_PRIVATE_KEY> The private key to your Nervos Layer 1 account. Make sure your account has been funded with Testnet CKBytes from the Testnet Faucet. Always make sure your private key is prefixed with "0x".
  2. <YOUR_ETH_ADDRESS> - The Ethereum address of your account from MetaMask. This will be used to receive funds on Layer 2. This can be found in MetaMask by clicking the address within the wallet as seen in step 2 of this tutorial.
  3. <SHANNONS_AMOUNT> - The amount of CKBytes to transfer, written in Shannons. A Shannon is a unit of measurement in Nervos that is the equivalent of a Satoshi in Bitcoin. We recommend depositing 1,000 CKBytes, which is the minimum number required by Godwoken. There are 100,000,000 Shannons in a CKByte, and this value must be expressed in Shannons. ie: 1,000 * 100,000,000 = 100,000,000,000
  4. <INSERT_TESTNET_RPC_URL> - The RPC URL of the Testnet CKB node you will use. This should be your local address if you are using a local node, or it can be a public address if you're using a public node.
    Local Testnet CKB Node URL: http://127.0.0.1:8114
    Public Testnet CKB Node URL: http://3.235.223.161:18114
  5. <INSERT_INDEXER_RPC_URL> - The RPC URL of the Testnet ckb-indexer you will use. This should be your local address if you are using a local indexer, or it can be a public address if you're using a public indexer.
    Local Testnet ckb-indexer URL: http://127.0.0.1:8116
    Public Testnet ckb-indexer URL: http://3.235.223.161:18116

Example final command with all values filled in:

node ./packages/tools/lib/account-cli.js deposit -l 0xD173313A51f8fc37BcF67569b463abd89d81844f -p 0x79682c20bbcaf7fcf18eb0c69b133c872227ceb88971090e7f2242c80cd54d18 -c 100000000000 -r http://3.235.223.161:18114 -i http://3.235.223.161:18116

Note: Minimum deposit value is 1000 CKB. If you try depositing amount lower than that it will fail.

Example Output:

LUMOS_CONFIG_NAME: AGGRON4
Indexer is syncing. Please wait...
Indexer synchronized.
Using ETH address: 0xD173313A51f8fc37BcF67569b463abd89d81844f
Using CKB address: ckt1qyq9u5vzgtklnqrr6cevra7w2utrsxmjgefs72sfju
Rollup type hash: 0x4cc2e6526204ae6a2e8fcf12f7ad472f41a1606d5b9624beebd215d780809f6a
Your address: 0x8016dcd1af7c8cceda53e4d2d2cd4e2924e245b6
Transaction hash: 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16
--------- wait for deposit transaction ----------
tx 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16 is pending, waited for 0 seconds
tx 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16 is pending, waited for 10 seconds
tx 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16 is proposed, waited for 20 seconds
tx 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16 is proposed, waited for 30 seconds
tx 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16 is committed, waited for 40 seconds
tx 0x332bdff2552a9ba63584a868707a9e23aadde02bd4caca0e3e37a106a326bf16 is committed!
CKB balance in Godwoken is: 2139996473241 Shannons.
Waiting for Layer 2 block producer to collect the deposit cell ... 0 seconds.
Your account id: 13
Waiting for Layer 2 block producer to collect the deposit cell ... 10 seconds.
Waiting for Layer 2 block producer to collect the deposit cell ... 20 seconds.
Waiting for Layer 2 block producer to collect the deposit cell ... 30 seconds.
Waiting for Layer 2 block producer to collect the deposit cell ... 40 seconds.
CKB balance in Godwoken is: 2239996473241 Shannons.
Deposit success!