Skip to content

TheWaWaR/godwoken-examples

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Godwoken Examples

This demo shows of how to use Godwoken.

The demo provides the following functionalities:

  • Deposit from a MetaMask powered address into Godwoken.
  • Deploy an Ethereum Smart Contract to Polyjuice running on Godwoken, we use SimpleStorage.
  • Submit a polyjuice transaction to set the value in SimpleStorage smart contract.
  • Execute (but do not submit) a transaction to fetch the current stored value in SimpleStorage smart contract.
  • Query the balance of a Godwoken account.
  • Make transfers between Godwoken accounts.
  • Withdraw from Godwoken back to a layer 1 CKB address.

Install dependencies

yarn run bootstrap

Update Demo Configs

Firstly copy config files.

cp <your godwoken `scripts-deploy-result.json`> packages/demo/src/configs/scripts-deploy-result.json
cp <your godwoken `config.toml`> packages/demo/src/configs/godwoken-config.json (convert config.toml to json format)
cp packages/demo/src/configs/config.json.sample packages/demo/src/configs/config.json
# then update `config.json` with your own config.

Deposit By CLI

Deposit CLI both support testnet and dev chain.

Build typescripts

yarn workspace @godwoken-examples/godwoken tsc 
yarn workspace @godwoken-examples/demo clean-cli && yarn workspace @godwoken-examples/demo build-cli

Deposit

Run deposit.js --help to see how to use this command.

LUMOS_CONFIG_FILE=<your lumos config json file> node ./packages/demo/build-cli/cli/deposit.js --help

Or Deposit SUDT

LUMOS_CONFIG_FILE=<your lumos config json file> node ./packages/demo/build-cli/cli/deposit_sudt.js --help

Deposit By Demo Page

Deposit and Deposit SUDT module only support testnet, other parts support both testnet and dev chain

Build typescripts

yarn workspace @godwoken-examples/godwoken tsc
yarn workspace @godwoken-examples/demo clean && yarn workspace @godwoken-examples/demo build

Start Server

yarn workspace @godwoken-examples/demo start

Open in browser

Open http://localhost:9000/html/index.html

Godwoken utils

Unlock Withdrawal

Run godwoken-cli.js --help to see how to use this command.

yarn workspace @godwoken-examples/godwoken tsc 
yarn workspace @godwoken-examples/tools tsc 

LUMOS_CONFIG_FILE=<your lumos config json file> node ./packages/tools/lib/godwoken-cli.js unlockWithdraw --help

Polyjuice

Create Creator account

Build typescripts

yarn workspace @godwoken-examples/godwoken tsc 
yarn workspace @godwoken-examples/polyjuice tsc 
yarn workspace @godwoken-examples/tools tsc 

Create creator account for polyjuice

Create account id for create polyjuice contract account (the creator_account_id config)

$ node packages/tools/lib/polyjuice-cli.js createCreatorAccount <from_id> <sudt_id> <rollup_type_hash> <privkey>

You can see <rollup_type_hash> when godwoken started.

<sudt_id> given 1 is for CKB Token.

<privkey> is a 0x prefixed hex string.

<from_id> is your user account, you can get the account id by:

$ node packages/tools/lib/godwoken-cli.js getAccountIdByScriptHash <script_hash>

You can get the script hash when deposition finished.

Update creator account config

polyjuice-cli.js createCreatorAccount will return an creator_account_id and write this to packages/demo/src/configs/config.json creator_account_ids.

And recompile demo

yarn workspace @godwoken-examples/demo clean && yarn workspace @godwoken-examples/demo build

Deploy an Ethereum contract

Also supported by Demo Page.

$ node packages/tools/lib/polyjuice-cli.js deploy <creator_account_id> <init_code> <rollup_type_hash> <privkey>

This will output the account id.

The <init_code> sample, please see SimpleStorage.bin .

Call an ethereum contract

Also supported by Demo Page.

$ node packages/tools/lib/polyjuice-cli.js call <to_id> <input_data> <rollup_type_hash> <privkey>

<to_id> is the account created in deploy step.

The <input_data> is generated by ethabi , please see SimpleStorage.calls.md .

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 77.2%
  • TypeScript 20.2%
  • HTML 2.5%
  • Solidity 0.1%