Skip to content

Commit 86fe278

Browse files
Add Set Up Your Project
1 parent 1758f29 commit 86fe278

File tree

2 files changed

+97
-198
lines changed

2 files changed

+97
-198
lines changed

llms.txt

Lines changed: 54 additions & 196 deletions
Original file line numberDiff line numberDiff line change
@@ -27843,13 +27843,54 @@ To demonstrate these techniques, the guide introduces a complete example scenari
2784327843

2784427844
Before you begin, ensure you've:
2784527845

27846-
- [Chopsticks](/develop/toolkit/parachains/fork-chains/chopsticks/get-started/){target=\_blank} installed (`npm i -g @acala-network/chopsticks`)
27846+
- [Chopsticks](/develop/toolkit/parachains/fork-chains/chopsticks/get-started/){target=\_blank} installed
2784727847
- Access to the endpoint or genesis file of the parachain you wish to fork
2784827848
- Set up your TypeScript project with the essential tools
2784927849

2785027850
If you haven't replayed or dry-run XCMs before, see the [Replay and Dry Run XCMs Using Chopsticks](/tutorials/interoperability/replay-and-dry-run-xcms/){target=\_blank} tutorial for step-by-step guidance.
2785127851

27852-
### Launch a Fork for Local Testing
27852+
### Set Up Your Project
27853+
27854+
Let's start by creating a dedicated workspace for your XCM observability demo.
27855+
27856+
1. Create a new directory and navigate into it:
27857+
27858+
```bash
27859+
mkdir -p xcm-obs-demo
27860+
cd xcm-obs-demo
27861+
```
27862+
27863+
2. Initialise a new Node project:
27864+
27865+
```bash
27866+
npm init -y
27867+
```
27868+
27869+
3. Install Chopsticks globally (recommended to avoid conflicts with local installs):
27870+
27871+
```bash
27872+
npm install -g @acala-network/chopsticks@latest
27873+
```
27874+
27875+
4. Install TypeScript and related tooling for local development:
27876+
27877+
```bash
27878+
npm install --save-dev typescript @types/node tsx
27879+
```
27880+
27881+
5. Install the required Polkadot packages:
27882+
27883+
```bash
27884+
npm install polkadot-api @polkadot-labs/hdkd @polkadot-labs/hdkd-helpers
27885+
```
27886+
27887+
6. Initialise the TypeScript config:
27888+
27889+
```bash
27890+
npx tsc --init
27891+
```
27892+
27893+
### Launch a Fork for XCM Observability Demo
2785327894

2785427895
To observe XCM tracing in action, fork the relevant chains locally using Chopsticks.
2785527896

@@ -40460,43 +40501,7 @@ Let's start by setting up Hardhat for your Storage contract project:
4046040501
6. Configure Hardhat by updating the `hardhat.config.js` file:
4046140502

4046240503
```javascript title="hardhat.config.js"
40463-
require("@nomicfoundation/hardhat-toolbox");
40464-
40465-
require("@parity/hardhat-polkadot");
40466-
40467-
const { vars } = require("hardhat/config");
40468-
40469-
/** @type import('hardhat/config').HardhatUserConfig */
40470-
module.exports = {
40471-
solidity: "0.8.28",
40472-
resolc: {
40473-
version: "1.5.2",
40474-
compilerSource: "npm",
40475-
},
40476-
networks: {
40477-
hardhat: {
40478-
polkavm: true,
40479-
nodeConfig: {
40480-
nodeBinaryPath: 'INSERT_PATH_TO_SUBSTRATE_NODE',
40481-
rpcPort: 8000,
40482-
dev: true,
40483-
},
40484-
adapterConfig: {
40485-
adapterBinaryPath: 'INSERT_PATH_TO_ETH_RPC_ADAPTER',
40486-
dev: true,
40487-
},
40488-
},
40489-
localNode: {
40490-
polkavm: true,
40491-
url: `http://127.0.0.1:8545`,
40492-
},
40493-
passetHub: {
40494-
polkavm: true,
40495-
url: 'https://testnet-passet-hub-eth-rpc.polkadot.io',
40496-
accounts: [vars.get("PRIVATE_KEY")],
40497-
},
40498-
},
40499-
};
40504+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/hardhat.config.js
4050040505
```
4050140506

4050240507
Ensure that `INSERT_PATH_TO_SUBSTRATE_NODE` and `INSERT_PATH_TO_ETH_RPC_ADAPTER` are replaced with the proper paths to the compiled binaries.
@@ -40526,27 +40531,7 @@ module.exports = {
4052640531
1. Create a new folder called `contracts` and create a `Storage.sol` file. Add the contract code from the previous tutorial:
4052740532

4052840533
```solidity title="Storage.sol"
40529-
// SPDX-License-Identifier: MIT
40530-
pragma solidity ^0.8.28;
40531-
40532-
contract Storage {
40533-
// State variable to store our number
40534-
uint256 private number;
40535-
40536-
// Event to notify when the number changes
40537-
event NumberChanged(uint256 newNumber);
40538-
40539-
// Function to store a new number
40540-
function store(uint256 newNumber) public {
40541-
number = newNumber;
40542-
emit NumberChanged(newNumber);
40543-
}
40544-
40545-
// Function to retrieve the stored number
40546-
function retrieve() public view returns (uint256) {
40547-
return number;
40548-
}
40549-
}
40534+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/contracts/Storage.sol
4055040535
```
4055140536

4055240537
2. Compile the contract:
@@ -40572,28 +40557,9 @@ Testing is a critical part of smart contract development. Hardhat makes it easy
4057240557
1. Create a folder for testing called `test`. Inside that directory, create a file named `Storage.js` and add the following code:
4057340558

4057440559
```javascript title="Storage.js"
40575-
const { expect } = require('chai');
40576-
const { ethers } = require('hardhat');
40577-
40578-
describe('Storage', function () {
40579-
let storage;
40580-
let owner;
40581-
let addr1;
40582-
40583-
beforeEach(async function () {
40584-
// Get signers
40585-
[owner, addr1] = await ethers.getSigners();
40586-
40587-
// Deploy the Storage contract
40588-
const Storage = await ethers.getContractFactory('Storage');
40589-
storage = await Storage.deploy();
40590-
await storage.waitForDeployment();
40591-
});
40592-
40593-
describe('Basic functionality', function () {
40560+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4059440561
// Add your logic here
40595-
});
40596-
});
40562+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4059740563
```
4059840564

4059940565
The `beforeEach` hook ensures stateless contract execution by redeploying a fresh instance of the Storage contract before each test case. This approach guarantees that each test starts with a clean and independent contract state by using `ethers.getSigners()` to obtain test accounts and `ethers.getContractFactory('Storage').deploy()` to create a new contract instance.
@@ -40603,9 +40569,7 @@ describe('Storage', function () {
4060340569
a. **Initial state verification** - ensures that the contract starts with a default value of zero, which is a fundamental expectation for the `Storage.sol` contract
4060440570

4060540571
```javascript title="Storage.js"
40606-
it('Should return 0 initially', async function () {
40607-
expect(await storage.retrieve()).to.equal(0);
40608-
});
40572+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4060940573
```
4061040574

4061140575
Explanation:
@@ -40617,13 +40581,7 @@ describe('Storage', function () {
4061740581
b. **Value storage test** - validate the core functionality of storing and retrieving a value in the contract
4061840582

4061940583
```javascript title="Storage.js"
40620-
it('Should update when store is called', async function () {
40621-
const testValue = 42;
40622-
// Store a value
40623-
await storage.store(testValue);
40624-
// Check if the value was updated
40625-
expect(await storage.retrieve()).to.equal(testValue);
40626-
});
40584+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4062740585
```
4062840586

4062940587
Explanation:
@@ -40635,13 +40593,7 @@ describe('Storage', function () {
4063540593
c. **Event emission verification** - confirm that the contract emits the correct event when storing a value, which is crucial for off-chain tracking
4063640594

4063740595
```javascript title="Storage.js"
40638-
it('Should emit an event when storing a value', async function () {
40639-
const testValue = 100;
40640-
// Check if the NumberChanged event is emitted with the correct value
40641-
await expect(storage.store(testValue))
40642-
.to.emit(storage, 'NumberChanged')
40643-
.withArgs(testValue);
40644-
});
40596+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4064540597
```
4064640598

4064740599
Explanation:
@@ -40653,14 +40605,7 @@ describe('Storage', function () {
4065340605
d. **Sequential value storage test** - check the contract's ability to store multiple values sequentially and maintain the most recent value
4065440606

4065540607
```javascript title="Storage.js"
40656-
it('Should allow storing sequentially increasing values', async function () {
40657-
const values = [10, 20, 30, 40];
40658-
40659-
for (const value of values) {
40660-
await storage.store(value);
40661-
expect(await storage.retrieve()).to.equal(value);
40662-
}
40663-
});
40608+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4066440609
```
4066540610

4066640611
Explanation:
@@ -40673,55 +40618,7 @@ describe('Storage', function () {
4067340618

4067440619
???--- code "View complete script"
4067540620
```javascript title="Storage.js"
40676-
const { expect } = require('chai');
40677-
const { ethers } = require('hardhat');
40678-
40679-
describe('Storage', function () {
40680-
let storage;
40681-
let owner;
40682-
let addr1;
40683-
40684-
beforeEach(async function () {
40685-
// Get signers
40686-
[owner, addr1] = await ethers.getSigners();
40687-
40688-
// Deploy the Storage contract
40689-
const Storage = await ethers.getContractFactory('Storage');
40690-
storage = await Storage.deploy();
40691-
await storage.waitForDeployment();
40692-
});
40693-
40694-
describe('Basic functionality', function () {
40695-
it('Should return 0 initially', async function () {
40696-
expect(await storage.retrieve()).to.equal(0);
40697-
});
40698-
40699-
it('Should update when store is called', async function () {
40700-
const testValue = 42;
40701-
// Store a value
40702-
await storage.store(testValue);
40703-
// Check if the value was updated
40704-
expect(await storage.retrieve()).to.equal(testValue);
40705-
});
40706-
40707-
it('Should emit an event when storing a value', async function () {
40708-
const testValue = 100;
40709-
// Check if the NumberChanged event is emitted with the correct value
40710-
await expect(storage.store(testValue))
40711-
.to.emit(storage, 'NumberChanged')
40712-
.withArgs(testValue);
40713-
});
40714-
40715-
it('Should allow storing sequentially increasing values', async function () {
40716-
const values = [10, 20, 30, 40];
40717-
40718-
for (const value of values) {
40719-
await storage.store(value);
40720-
expect(await storage.retrieve()).to.equal(value);
40721-
}
40722-
});
40723-
});
40724-
});
40621+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/test/Storage.js
4072540622
```
4072640623

4072740624
2. Run the tests:
@@ -40750,13 +40647,7 @@ describe('Storage', function () {
4075040647
1. Create a new folder called`ignition/modules`. Add a new file named `StorageModule.js` with the following logic:
4075140648

4075240649
```javascript title="StorageModule.js"
40753-
const { buildModule } = require('@nomicfoundation/hardhat-ignition/modules');
40754-
40755-
module.exports = buildModule('StorageModule', (m) => {
40756-
const storage = m.contract('Storage');
40757-
40758-
return { storage };
40759-
});
40650+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/ignition/modules/StorageModule.js
4076040651
```
4076140652

4076240653
2. Deploy to the local network:
@@ -40828,40 +40719,7 @@ To interact with your deployed contract:
4082840719
1. Create a new folder named `scripts` and add the `interact.js` with the following content:
4082940720

4083040721
```javascript title="interact.js"
40831-
const hre = require('hardhat');
40832-
40833-
async function main() {
40834-
// Replace with your deployed contract address
40835-
const contractAddress = 'INSERT_DEPLOYED_CONTRACT_ADDRESS';
40836-
40837-
// Get the contract instance
40838-
const Storage = await hre.ethers.getContractFactory('Storage');
40839-
const storage = await Storage.attach(contractAddress);
40840-
40841-
// Get current value
40842-
const currentValue = await storage.retrieve();
40843-
console.log('Current stored value:', currentValue.toString());
40844-
40845-
// Store a new value
40846-
const newValue = 42;
40847-
console.log(`Storing new value: ${newValue}...`);
40848-
const tx = await storage.store(newValue);
40849-
40850-
// Wait for transaction to be mined
40851-
await tx.wait();
40852-
console.log('Transaction confirmed');
40853-
40854-
// Get updated value
40855-
const updatedValue = await storage.retrieve();
40856-
console.log('Updated stored value:', updatedValue.toString());
40857-
}
40858-
40859-
main()
40860-
.then(() => process.exit(0))
40861-
.catch((error) => {
40862-
console.error(error);
40863-
process.exit(1);
40864-
});
40722+
Error fetching snippet from https://raw.githubusercontent.com/polkadot-developers/polkavm-hardhat-examples/refs/tags/v0.0.7/storage-hardhat/scripts/interact.js
4086540723
```
4086640724

4086740725
Ensure that `INSERT_DEPLOYED_CONTRACT_ADDRESS` is replaced with the value obtained in the previous step.

tutorials/interoperability/xcm-observability.md

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,54 @@ To demonstrate these techniques, the guide introduces a complete example scenari
2323

2424
Before you begin, ensure you've:
2525

26-
- [Chopsticks](/develop/toolkit/parachains/fork-chains/chopsticks/get-started/){target=\_blank} installed (`npm i -g @acala-network/chopsticks`)
26+
- [Chopsticks](/develop/toolkit/parachains/fork-chains/chopsticks/get-started/){target=\_blank} installed
2727
- Access to the endpoint or genesis file of the parachain you wish to fork
2828
- Set up your TypeScript project with the essential tools
2929

3030
If you haven't replayed or dry-run XCMs before, see the [Replay and Dry Run XCMs Using Chopsticks](/tutorials/interoperability/replay-and-dry-run-xcms/){target=\_blank} tutorial for step-by-step guidance.
3131

32-
### Launch a Fork for Local Testing
32+
### Set Up Your Project
33+
34+
Let's start by creating a dedicated workspace for your XCM observability demo.
35+
36+
1. Create a new directory and navigate into it:
37+
38+
```bash
39+
mkdir -p xcm-obs-demo
40+
cd xcm-obs-demo
41+
```
42+
43+
2. Initialise a new Node project:
44+
45+
```bash
46+
npm init -y
47+
```
48+
49+
3. Install Chopsticks globally (recommended to avoid conflicts with local installs):
50+
51+
```bash
52+
npm install -g @acala-network/chopsticks@latest
53+
```
54+
55+
4. Install TypeScript and related tooling for local development:
56+
57+
```bash
58+
npm install --save-dev typescript @types/node tsx
59+
```
60+
61+
5. Install the required Polkadot packages:
62+
63+
```bash
64+
npm install polkadot-api @polkadot-labs/hdkd @polkadot-labs/hdkd-helpers
65+
```
66+
67+
6. Initialise the TypeScript config:
68+
69+
```bash
70+
npx tsc --init
71+
```
72+
73+
### Launch a Fork for XCM Observability Demo
3374

3475
To observe XCM tracing in action, fork the relevant chains locally using Chopsticks.
3576

0 commit comments

Comments
 (0)