Plian
Chinese
Chinese
  • Overview
  • Links
  • Downloads
  • FAQ
    • Node Status
    • Full Balance
    • Flow and FAQ on Becoming a Validator
    • Delegation
    • Staking Rewards
    • Monitor
    • PIScan
    • PIWallet
    • Cross-Chain Transactions
    • DApps
  • About The Blockchain
    • Multichain Framework
    • PDBFT 2.0 Consensus Algorithm
    • Validator Nodes
    • Building with Plian
  • Using The Blockchain
    • Overview
    • Delegating or Staking PI
    • Validator Node Guides
      • Express Node Setup Guide
      • Setting Up a Validator Node
      • Registering Your Node as Validator
      • Submitting Your Vote as Validator
      • Revealing Your Vote
      • Removing Your Node From the Candidate List
      • Alternate Installation Instructions
        • Building From the Source
        • Running Pchain in Docker
        • Installation Instructions for Ubuntu
        • Installation Instructions for Mac OS X
        • Installation Instructions for Windows 10
      • What is FullBalance
    • Token Swaps
    • Plian Javascript Console
    • PIwallet
      • Web
      • Desktop Wallet
        • Light Wallet Mode
        • Local Node Mode
      • Mobile Wallets
      • How to Deploy a Smart Contract
    • PMetamask
    • Advanced Features
      • Command Line Options
      • Management APIs
      • JSON RPC API
      • How to Sync and Run Testnet
  • For Developers
    • How to connect Metamask to Plian
    • How to deploy smart contract on Plian via Metamask + Remix
    • PWeb3 Javascript API
    • How to Create Your Own Subchain
    • Writing Smart Contracts With Solidity
      • Introduction to Smart Contracts
      • Installing the Solidity Compiler
      • Solidity by Example
      • Solidity in Depth
        • Layout of a Solidity Source File
        • Structure of a Contract
        • Types
        • Units and Globally Available Variables
        • Expressions and Control Structures
        • Contracts
        • Solidity Assembly
        • Miscellaneous
      • Security Considerations
      • Resources
      • Using the compiler
      • Contract Metadata
      • Contract ABI Specification
      • Yul
      • Style Guide
      • Common Patterns
      • List of Known Bugs
      • Contributing
      • Frequently Asked Questions
      • LLL
      • Index
Powered by GitBook
On this page
  • Create Subchain
  • Join Subchain
  • Check

Was this helpful?

  1. For Developers

How to Create Your Own Subchain

Before you create your own subchain, make sure you have done things below:

  • sync and run pchain

  • have at least one address and one consensus key

  • have at least 200k PI on your address

Here is an example of priv_validator.json which stores your address and consensus keys:

{
"address": "4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C",
"consensus_priv_key": [
        4,
        "D8AF52E355CD070ED3401800CBC920B6E94F3C49B42808C3049BF7BDB1FA3B19"
],
"consensus_pub_key": [
        4,
        "085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0"
]
}

Do not create a different subchain with the same address. You can find this priv_validator.json file in the datadir/.pchain/pchain directory.

Create Subchain

Suppose you are going to create a subchain with a chain id as “mychain”, and you want your subchain to start with one validator with a minimum of 100k deposit PI.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["from","chainId", "minValidators", "minDepositAmount", "startBlock","endBlock"],"id":1}' localhost:6969/pchain

In this case, the command should be:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_createChildChain","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C","mychain", "0x1", "0x152D02C7E14AF6800000", "0x32","0x7D0"],"id":1}' localhost:6969/pchain

You can set parameter startBlock very small and set parameter endBlock very big to make sure you won't miss it. Once successful, your account will deposit 100k PI on the subchain. If you didn't finish the second step, the deposit will be back to your account once the main chain reaches the endBlock height.

Note: This is only the first step, you need to finish the second step, or the chain won't start.

Join Subchain

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["address", "consensus private key"],"id":1}' localhost:6969/pchain

In this case, the command should be:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_signAddress","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C", "0xD8AF52E355CD070ED3401800CBC920B6E94F3C49B42808C3049BF7BDB1FA3B19"],"id":1}' localhost:6969/pchain
//"0x1214608bcdf2e464b2d37d19b1b671482253e275d33079264045253fbb18689385ac0d5b4128d0c593211588deafd9ea2507b4858bdd42aaef3999045c0407ae"

Remember the return hash.

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_joinChildChain
.","params":["from","pubkey", "chainId", "depositAmount", "signature"],"id":1}' localhost:6969/pchain

In this case, the command should be:

curl -X POST -H "Content-Type:application/json" --data '{"jsonrpc":"2.0","method":"chain_joinChildChain","params":["0x4CACBCBF218679DCC9574A90A2061BCA4A8D8B6C","085586D41F70435700850E19B7DE54B3E793C5EC4C6EC502D19030EF4F2122823E5A765E56CBA7B4C57E50561F77B022313C39895CA303F3C95D7B7282412F334778B95ACE046A79AEA4DB148334527250C8895AC5DB80459BF5D367236B59AF2DB5C0254E30A6D8CD1FA10AB8A5D872F5EBD312D3160D3E4DD496973BDC75E0", "mychain", "0x152D02C7E14AF6800000", "0x1214608bcdf2e464b2d37d19b1b671482253e275d33079264045253fbb18689385ac0d5b4128d0c593211588deafd9ea2507b4858bdd42aaef3999045c0407ae"],"id":1}' localhost:6969/pchain

After this transaction succeeds and the main chain reaches startBlock height, your chain will start.

Check

Once your chain started, you will find a directory named with chain id under datadir/.pchain/, in this case, it should be datadir/.pchain/mychain, you can attach to its console by command:

./bin/pchain attach .pchain/mychain/pchain.ipc
PreviousPWeb3 Javascript APINextWriting Smart Contracts With Solidity

Last updated 4 years ago

Was this helpful?

You can create subchain by .

Before you join the subchain, you need to generate a signature signed by your consensus private key. You can generate it by .

Now you need to join the subchain, in this example, you need at least one validator with at least 100k deposit PI to let your subchain start. You can join the subchain by .

RPC chain_createChildChain
RPC chain_signAddress
RPC chain_joinChildChain