Chopsticks by Acala
Introduction
Chopsticks provides a developer-friendly method of locally forking existing Substrate based chains. It allows for the replaying of blocks to easily examine how extrinsics effect state, the forking of multiple blocks for XCM testing, and more. This allows developers to test and experiment with their own custom blockchain configurations in a local development environment, without the need to deploy a live network.
Overall, Chopsticks aims to simplify the process of building blockchain applications on Substrate and make it accessible to a wider range of developers.
Forking Phron with Chopsticks
To use Chopsticks, you can install it as a package with the Node package manager or Yarn:
Once installed, you can run commands with the Node package executor. For example, this runs Chopstick's base command:
To run Chopsticks, you will need some sort of configuration, typically through a file. Chopsticks' source repository includes a set of YAML configuration files that can be used to create a local copy of a variety of Substrate chains. You can download the configuration files from the source repository's configs
folder.
Phron all have default files available:
These are the settings that can be included in the config file:
You can use the configuration file with the base command npx @acala-network/chopsticks@latest
to fork assets by providing it with the --config
flag.
You can use a raw GitHub URL of the default configuration files, a path to a local configuration file, or simply use the chain's name for the --config
flag. For example, the following commands all use Phron's configuration in the same way:
Note!If using a file path, make sure you've downloaded the Phron configuration file, or have created your own.
A configuration file is not necessary, however. All of the settings (except genesis
and timestamp
) can also be passed as flags to configure the environment completely in the command line. For example, the following command forks Phron at block 100.
Quickstart
The simplest way to fork Phron is through the configuration files that are stored in the Chopsticks GitHub repository:
Interacting with a Fork
When running a fork, by default it will be accessible at:
You will be able to interact with the parachain via libraries such as Polkadot.js and its user interface, Polkadot.js Apps.
You can interact with Chopsticks via the Polkadot.js Apps hosted user interface. To do so, visit the page and take the following steps:
Click the PhronesisTelem in the top left
Go to the bottom and open Development
Select the Custom endpoint and enter
ws://localhost:8000
Click the Switch button
You should now be able to interact with the fork as you would an active parachain or relay chain.
Note!If your browser cannot connect to the WebSocket endpoint provided by Chopsticks, you might need to allow insecure connections for the Polkadot.js Apps URL. Another solution is to run the Docker version of Polkadot.js Apps.
Replaying Blocks
In the case where you would like to replay a block and retrieve its information to dissect the effects of an extrinsic, you can use the npx @acala-network/chopsticks@latest run-block
command. Its following flags are:
For example, running the following command will re-run Phron's block 1000, and write the storage diff and other data in a phron-output.json
file:
WebSocket Commands
Chopsticks' internal websocket server has special endpoints that allows the manipulation of the local Substrate chain. These are the methods that can be invoked:
The parameters above are formatted in the following ways:
options
{ "to": number, "count": number } - a JSON object where"to"
will create blocks up to a certain value, and"count"
will increase by a certain number of blocks. Use only one entry at a time within the JSON objectvalues
Object - a JSON object resembling the path to a storage value, similar to what you would retrieve via Polkadot.jsblockHash
string - optional, the blockhash at which the storage value is changeddate
Date - a Date string (compatible with the JavaScript Date library) that will change the time stamp from which the next blocks being created will be at. All future blocks will be sequentially after that point in timehashOrNumber
number | string - if found, the chain head will be set to the block with the block number or block hash of this value
Each method can be invoked by connecting to the websocket (ws://localhost:8000
by default) and sending the data and parameters in the following format. Replace METHOD_NAME
with the name of the method, and replace or delete PARAMETER_1
and PARAMETER_2
with the parameter data relevant to the method:
This tutorial is for educational purposes only. As such, any contracts or code created in this tutorial should not be used in production.The information presented herein has been provided by third parties and is made available solely for general information purposes. Phron does not endorse any project listed and described on the Phron Doc Website (https://docs.Phron.ai/). Phron does not warrant the accuracy, completeness or usefulness of this information. Any reliance you place on such information is strictly at your own risk. Phron disclaims all liability and responsibility arising from any reliance placed on this information by you or by anyone who may be informed of any of its contents. All statements and/or opinions expressed in these materials are solely the responsibility of the person or entity providing those materials and do not necessarily represent the opinion of Phron. The information should not be construed as professional or financial advice of any kind. Advice from a suitably qualified professional should always be sought in relation to any particular matter or circumstance. The information herein may link to or integrate with other websites operated or content provided by third parties, and such other websites may link to this website. Phron has no control over any such other websites or their content and will have no liability arising out of or related to such websites or their content. The existence of any such link does not constitute an endorsement of such websites, the content of the websites, or the operators of the websites. These links are being provided to you only as a convenience and you release and hold Phron harmless from any and all liability arising from your use of this information or the information provided by any third-party website or service.
Last updated