You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -140,7 +140,7 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
140
140
1. Open the `runtime/Cargo.toml` file and locate the `[dependencies]` section. Add pallet-utility as one of the features for the `polkadot-sdk` dependency with the following line:
141
141
142
142
```toml hl_lines="4" title="runtime/Cargo.toml"
143
-
143
+
[dependencies]
144
144
...
145
145
polkadot-sdk = { workspace = true, features = [
146
146
"pallet-utility",
@@ -151,7 +151,7 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
151
151
2. In the same `[dependencies]` section, add the custom pallet that you built from scratch with the following line:
@@ -1634,13 +1684,53 @@ To build the smart contract, follow the steps below:
1634
1684
6. Add the getter and setter functions:
1635
1685
1636
1686
```solidity
1637
-
1687
+
// SPDX-License-Identifier: MIT
1688
+
pragma solidity ^0.8.28;
1689
+
1690
+
contract Storage {
1691
+
// State variable to store our number
1692
+
uint256 private number;
1693
+
1694
+
// Event to notify when the number changes
1695
+
event NumberChanged(uint256 newNumber);
1696
+
1697
+
// Function to store a new number
1698
+
function store(uint256 newNumber) public {
1699
+
number = newNumber;
1700
+
emit NumberChanged(newNumber);
1701
+
}
1702
+
1703
+
// Function to retrieve the stored number
1704
+
function retrieve() public view returns (uint256) {
1705
+
return number;
1706
+
}
1707
+
}
1638
1708
```
1639
1709
1640
1710
??? code "Complete Storage.sol contract"
1641
1711
1642
1712
```solidity title="Storage.sol"
1643
-
1713
+
// SPDX-License-Identifier: MIT
1714
+
pragma solidity ^0.8.28;
1715
+
1716
+
contract Storage {
1717
+
// State variable to store our number
1718
+
uint256 private number;
1719
+
1720
+
// Event to notify when the number changes
1721
+
event NumberChanged(uint256 newNumber);
1722
+
1723
+
// Function to store a new number
1724
+
function store(uint256 newNumber) public {
1725
+
number = newNumber;
1726
+
emit NumberChanged(newNumber);
1727
+
}
1728
+
1729
+
// Function to retrieve the stored number
1730
+
function retrieve() public view returns (uint256) {
1731
+
return number;
1732
+
}
1733
+
}
1644
1734
```
1645
1735
1646
1736
## Understanding the Code
@@ -2004,7 +2094,23 @@ To create the ERC-20 contract, you can follow the steps below:
2004
2094
3. Now, paste the following ERC-20 contract code into the editor:
2005
2095
2006
2096
```solidity title="MyToken.sol"
2007
-
2097
+
// SPDX-License-Identifier: MIT
2098
+
// Compatible with OpenZeppelin Contracts ^5.0.0
2099
+
pragma solidity ^0.8.22;
2100
+
2101
+
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
2102
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
2103
+
2104
+
contract MyToken is ERC20, Ownable {
2105
+
constructor(address initialOwner)
2106
+
ERC20("MyToken", "MTK")
2107
+
Ownable(initialOwner)
2108
+
{}
2109
+
2110
+
function mint(address to, uint256 amount) public onlyOwner {
2111
+
_mint(to, amount);
2112
+
}
2113
+
}
2008
2114
```
2009
2115
2010
2116
The key components of the code above are:
@@ -2155,7 +2261,26 @@ To create the NFT contract, you can follow the steps below:
2155
2261
3. Now, paste the following NFT contract code into the editor.
2156
2262
2157
2263
```solidity title="MyNFT.sol"
2158
-
2264
+
// SPDX-License-Identifier: MIT
2265
+
// Compatible with OpenZeppelin Contracts ^5.0.0
2266
+
pragma solidity ^0.8.22;
2267
+
2268
+
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
2269
+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
2270
+
2271
+
contract MyToken is ERC721, Ownable {
2272
+
uint256 private _nextTokenId;
2273
+
2274
+
constructor(address initialOwner)
2275
+
ERC721("MyToken", "MTK")
2276
+
Ownable(initialOwner)
2277
+
{}
2278
+
2279
+
function safeMint(address to) public onlyOwner {
2280
+
uint256 tokenId = _nextTokenId++;
2281
+
_safeMint(to, tokenId);
2282
+
}
2283
+
}
2159
2284
```
2160
2285
2161
2286
The key components of the code above are:
@@ -5654,7 +5779,8 @@ The [`XcmRouter`](https://paritytech.github.io/polkadot-sdk/master/pallet_xcm/pa
5654
5779
For instance, the Kusama network employs the [`ChildParachainRouter`](https://paritytech.github.io/polkadot-sdk/master/polkadot_runtime_common/xcm_sender/struct.ChildParachainRouter.html){target=\_blank}, which restricts routing to [Downward Message Passing (DMP)](https://wiki.polkadot.com/learn/learn-xcm-transport/#dmp-downward-message-passing){target=\_blank} from the relay chain to parachains, ensuring secure and controlled communication.
For more details about XCM transport protocols, see the [XCM Channels](/develop/interoperability/xcm-channels/){target=\_blank} page.
@@ -6476,19 +6602,69 @@ The `xcm-emulator` provides macros for defining a mocked testing environment. Ch
6476
6602
- **[`decl_test_parachains`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L596){target=\_blank}**: Defines runtime and configuration for parachains. Example:
- **[`decl_test_bridges`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L1221){target=\_blank}**: Creates bridges between chains, specifying the source, target, and message handler. Example:
6483
6634
6484
6635
```rust
6485
-
6636
+
decl_test_bridges! {
6637
+
pub struct RococoWestendMockBridge {
6638
+
source = BridgeHubRococoPara,
6639
+
target = BridgeHubWestendPara,
6640
+
handler = RococoWestendMessageHandler
6641
+
},
6642
+
pub struct WestendRococoMockBridge {
6643
+
source = BridgeHubWestendPara,
6644
+
target = BridgeHubRococoPara,
6645
+
handler = WestendRococoMessageHandler
6646
+
}
6647
+
}
6486
6648
```
6487
6649
6488
6650
- **[`decl_test_networks`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L958){target=\_blank}**: Defines a testing network with relay chains, parachains, and bridges, implementing message transport and processing logic. Example:
6489
6651
6490
6652
```rust
6491
-
6653
+
decl_test_networks! {
6654
+
pub struct WestendMockNet {
6655
+
relay_chain = Westend,
6656
+
parachains = vec![
6657
+
AssetHubWestend,
6658
+
BridgeHubWestend,
6659
+
CollectivesWestend,
6660
+
CoretimeWestend,
6661
+
PeopleWestend,
6662
+
PenpalA,
6663
+
PenpalB,
6664
+
],
6665
+
bridge = ()
6666
+
},
6667
+
}
6492
6668
```
6493
6669
6494
6670
By leveraging these macros, developers can customize their testing networks by defining relay chains and parachains tailored to their needs. For guidance on implementing a mock runtime for a Polkadot SDK-based chain, refer to the [Pallet Testing](/develop/parachains/testing/pallet-testing/){target=\_blank} article.
0 commit comments