Skip to content

Latest commit

 

History

History
157 lines (111 loc) · 5.76 KB

kuai-cli-deploy-contract.md

File metadata and controls

157 lines (111 loc) · 5.76 KB

How to deploy contracts with kuai-cli

deploy contract workflow by builtin signer (directly deploy):

  1. Create a new contract, skip this step if the contract already exists (How to import existent contract)
  • kuai contract new --name [contract-name]

    $ kuai contract new --name always-success
    
    # New contract "always-success"
    #     Created binary (application) `always-success` package
    # Rewrite Cargo.toml
    # Rewrite capsule.toml
    # Done
  1. Build contract
  • kuai contract build --name [contract-name] --release

    $ kuai contract build --name always-success --release
    
    # Building contract always-success
    #    Compiling always-success v0.1.0 (/code/contracts/always-success)
    # Done
  1. Deploy contract
  • kuai contract deploy --name [contract-name] --from [0x.....] --signer ckb-cli

    $ kuai contract deploy --name always-success --from ckt1qyqw8yx5hx6vwcm7eqren0d0v39wvfwdhy3q2807pp --signer ckb-cli
    
    # [warn] ANYONE_CAN_PAY script info not found in config!
    # [warn] OMNILOCK script info not found in config!
    # [warn] `config` changed, regenerate lockScriptInfos!
    # The address format generated by generateAddress or scriptToAddress will be deprecated, please migrate to encodeToAddress to generate the new ckb2021 full format address as soon as possible
    # Input ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq0rjr2tndx8vdlvspuehkhkgjhxyhxmjgsqw8hsk's password for sign messge by ckb-cli:
    # deploy success, txHash:  0x7507b59b5f715c0fcd83d55df5569d72ff1cb05cd399afe1f366e03918827a58

deploy contract workflow by export tx:

  1. kuai contract deploy --name [contract-name] --from [0x.....] --export [transaction json file]

    $ kuai contract deploy --name always-success --from ckt1qyqw8yx5hx6vwcm7eqren0d0v39wvfwdhy3q2807pp --export ./tx.json
    
    # [warn] ANYONE_CAN_PAY script info not found in config!
    # [warn] OMNILOCK script info not found in config!
    # [warn] `config` changed, regenerate lockScriptInfos!
  2. ckb-cli tx sign-inputs --tx-file [transaction json file] --from-account 0xe390d4b9b4c7637ec80799bdaf644ae625cdb922 --add-signatures

    $ ckb-cli tx sign-inputs --tx-file ./tx.json --from-account 0xe390d4b9b4c7637ec80799bdaf644ae625cdb922 --add-signatures
    
    # Password:
    # - lock-arg: 0xe390d4b9b4c7637ec80799bdaf644ae625cdb922
    #   signature: 0xf3af55aa4c9d6923852465a33d625ff2b5489409908259d79d6aa5bf15a407f10ec32cdd9a9ebff837cdccc2850fc533cab8f08a4c701b57e75530c329f56be201
  3. ckb-cli tx send --tx-file [transaction json file]

    $ ckb-cli tx send --tx-file ./tx.json
    
    # 0xfd79d9c3e562b2c5c51df39e49fbb906c63cf2e33e5dbe2bbff12345fa4e6c72

export tx workflow with multisig

  1. kuai contract deploy --name [contract-name] --from multisig [R] [M] [...args] --export [transaction json file]

    $ kuai contract deploy --name always-success  --from multisig 0 2 0xe390d4b9b4c7637ec80799bdaf644ae625cdb922 0xb6ddba87bb5af5f053b1ae5bcbc7f4de03479f7e --export ./tx.json
    
    # [warn] ANYONE_CAN_PAY script info not found in config!
    # [warn] OMNILOCK script info not found in config!
    # [warn] `config` changed, regenerate lockScriptInfos!
    # The address format generated by generateAddress or scriptToAddress will be deprecated, please migrate to encodeToAddress to generate the new ckb2021 full format address as soon as possible
  2. Sign transactions according to multi-signature address: ckb-cli tx sign-inputs --tx-file [transaction json file] --from-account [args] --add-signatures

    # sign by 0xe390d4b9b4c7637ec80799bdaf644ae625cdb922
    $ ckb-cli tx sign-inputs --tx-file ./tx.json --from-account 0xe390d4b9b4c7637ec80799bdaf644ae625cdb922 --add-signatures
    
    # Password:
    # - lock-arg: 0x9ab40977fbad98c42cb0688cb10557a76f32c7ff
    #   signature: 0x2395d9d3fde764a6ba78b26699dab410d3609c0303c436768d24add978a64a8c4c4653051fe88124e9f2acb139179f291a40f79ebad93dac3433ad10b39415dd00
    # sign by 0xb6ddba87bb5af5f053b1ae5bcbc7f4de03479f7e
    $ ckb-cli tx sign-inputs --tx-file ./tx.json --from-account 0xb6ddba87bb5af5f053b1ae5bcbc7f4de03479f7e --add-signatures
    
    # Password:
    # - lock-arg: 0x9ab40977fbad98c42cb0688cb10557a76f32c7ff
    #   signature: 0x6efc1f6359b34fc6bc7edb32059947b61b9914272bda2ed7a7b1aeb0d7d272db7121fcab8cbe25ef8947a0ab1019dcaae3c5f83a9c0f6f486a81fe9787bc16cd01
  3. ckb-cli tx send --tx-file [transaction json file]

    $ ckb-cli tx send --tx-file ./tx.json
    
    # 0xa0fad2950093488baf41b25f3459482b5c7870b21f8d2bb709a731417cb99e33

How to import contract to kuai project

Typically, the file directory of a ckb contract looks something like this:

.
├── Cargo.toml
└── src
    ├── entry.rs
    ├── error.rs
    └── main.rs
  1. Copy all of this directory directly into the kuai's convention directory where the contracts are placed, which by default should be/contract/contracts/

  2. Edit the /contract/cargo.toml file to add information about the contract to [workspace], e.g.

    [workspace]
    members = ["tests", "contracts/kuai-mvp-contract", "types", "contracts/always-success"]

How to deploy contract to other network

  • kuai contract deploy --name [contract-name] --from [0x.....] --network [networkname]
  • or set network to .env file

Tips: add more network config

Kuai currently has three default settings for networks, testnet / mainnet / devnet, and users can also add custom network

  • edit kuai.config.js of project and add network tor networks field

    networks: {
        [networkname: string]: {
            rpcUrl: string
            prefix: string
            scripts?: Record<string, ScriptConfig>
        }
    }