Skip to content

Commit e4de6be

Browse files
nhussein11Telucero
andauthored
Add Overview and Eth precompiles (new IA) (#1140)
* fix: add eth precompiles * Enhance precompiles documentation by adding user interaction details and removing outdated standard precompiles table. * Add link to sample contracts for precompiles in documentation * fix: llms * fixes * resolve conflicts * applied feedback --------- Co-authored-by: Taylor Lucero <[email protected]> Co-authored-by: Taylor Lucero <[email protected]>
1 parent 4201746 commit e4de6be

31 files changed

+545
-5559
lines changed

.ai/categories/basics.md

Lines changed: 16 additions & 190 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
256256
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:
257257

258258
```toml hl_lines="4" title="runtime/Cargo.toml"
259-
[dependencies]
259+
260260
...
261261
polkadot-sdk = { workspace = true, features = [
262262
"pallet-utility",
@@ -267,19 +267,17 @@ First, you'll update the runtime's `Cargo.toml` file to include the Utility pall
267267
2. In the same `[dependencies]` section, add the custom pallet that you built from scratch with the following line:
268268

269269
```toml hl_lines="3" title="Cargo.toml"
270-
[dependencies]
270+
271271
...
272-
custom-pallet = { path = "../pallets/custom-pallet", default-features = false }
272+
273273
```
274274

275275
3. In the `[features]` section, add the custom pallet to the `std` feature list:
276276

277277
```toml hl_lines="5" title="Cargo.toml"
278-
[features]
279-
default = ["std"]
280-
std = [
278+
281279
...
282-
"custom-pallet/std",
280+
283281
...
284282
]
285283
```
@@ -2701,53 +2699,13 @@ To build the smart contract, follow the steps below:
27012699
6. Add the getter and setter functions:
27022700

27032701
```solidity
2704-
// SPDX-License-Identifier: MIT
2705-
pragma solidity ^0.8.28;
2706-
2707-
contract Storage {
2708-
// State variable to store our number
2709-
uint256 private number;
2710-
2711-
// Event to notify when the number changes
2712-
event NumberChanged(uint256 newNumber);
2713-
2714-
// Function to store a new number
2715-
function store(uint256 newNumber) public {
2716-
number = newNumber;
2717-
emit NumberChanged(newNumber);
2718-
}
2719-
2720-
// Function to retrieve the stored number
2721-
function retrieve() public view returns (uint256) {
2722-
return number;
2723-
}
2724-
}
2702+
27252703
```
27262704

27272705
??? code "Complete Storage.sol contract"
27282706

27292707
```solidity title="Storage.sol"
2730-
// SPDX-License-Identifier: MIT
2731-
pragma solidity ^0.8.28;
2732-
2733-
contract Storage {
2734-
// State variable to store our number
2735-
uint256 private number;
2736-
2737-
// Event to notify when the number changes
2738-
event NumberChanged(uint256 newNumber);
2739-
2740-
// Function to store a new number
2741-
function store(uint256 newNumber) public {
2742-
number = newNumber;
2743-
emit NumberChanged(newNumber);
2744-
}
2745-
2746-
// Function to retrieve the stored number
2747-
function retrieve() public view returns (uint256) {
2748-
return number;
2749-
}
2750-
}
2708+
27512709
```
27522710

27532711
## Understanding the Code
@@ -3385,23 +3343,7 @@ To create the ERC-20 contract, you can follow the steps below:
33853343
3. Now, paste the following ERC-20 contract code into the editor:
33863344

33873345
```solidity title="MyToken.sol"
3388-
// SPDX-License-Identifier: MIT
3389-
// Compatible with OpenZeppelin Contracts ^5.0.0
3390-
pragma solidity ^0.8.22;
3391-
3392-
import {ERC20} from "@openzeppelin/contracts/token/ERC20/ERC20.sol";
3393-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
3394-
3395-
contract MyToken is ERC20, Ownable {
3396-
constructor(address initialOwner)
3397-
ERC20("MyToken", "MTK")
3398-
Ownable(initialOwner)
3399-
{}
3400-
3401-
function mint(address to, uint256 amount) public onlyOwner {
3402-
_mint(to, amount);
3403-
}
3404-
}
3346+
34053347
```
34063348

34073349
The key components of the code above are:
@@ -3719,26 +3661,7 @@ To create the NFT contract, you can follow the steps below:
37193661
3. Now, paste the following NFT contract code into the editor.
37203662

37213663
```solidity title="MyNFT.sol"
3722-
// SPDX-License-Identifier: MIT
3723-
// Compatible with OpenZeppelin Contracts ^5.0.0
3724-
pragma solidity ^0.8.22;
3725-
3726-
import {ERC721} from "@openzeppelin/contracts/token/ERC721/ERC721.sol";
3727-
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
3728-
3729-
contract MyToken is ERC721, Ownable {
3730-
uint256 private _nextTokenId;
3731-
3732-
constructor(address initialOwner)
3733-
ERC721("MyToken", "MTK")
3734-
Ownable(initialOwner)
3735-
{}
3736-
3737-
function safeMint(address to) public onlyOwner {
3738-
uint256 tokenId = _nextTokenId++;
3739-
_safeMint(to, tokenId);
3740-
}
3741-
}
3664+
37423665
```
37433666

37443667
The key components of the code above are:
@@ -8301,16 +8224,7 @@ The [`Account` data type](https://paritytech.github.io/polkadot-sdk/master/frame
83018224
The code snippet below shows how accounts are defined:
83028225

83038226
```rs
8304-
/// The full account information for a particular account ID.
8305-
#[pallet::storage]
8306-
#[pallet::getter(fn account)]
8307-
pub type Account<T: Config> = StorageMap<
8308-
_,
8309-
Blake2_128Concat,
8310-
T::AccountId,
8311-
AccountInfo<T::Nonce, T::AccountData>,
8312-
ValueQuery,
8313-
>;
8227+
83148228
```
83158229

83168230
The preceding code block defines a storage map named `Account`. The `StorageMap` is a type of on-chain storage that maps keys to values. In the `Account` map, the key is an account ID, and the value is the account's information. Here, `T` represents the generic parameter for the runtime configuration, which is defined by the pallet's configuration trait (`Config`).
@@ -8334,24 +8248,7 @@ For a detailed explanation of storage maps, see the [`StorageMap`](https://parit
83348248
The `AccountInfo` structure is another key element within the [System pallet](https://paritytech.github.io/polkadot-sdk/master/src/frame_system/lib.rs.html){target=\_blank}, providing more granular details about each account's state. This structure tracks vital data, such as the number of transactions and the account’s relationships with other modules.
83358249

83368250
```rs
8337-
/// Information of an account.
8338-
#[derive(Clone, Eq, PartialEq, Default, RuntimeDebug, Encode, Decode, TypeInfo, MaxEncodedLen)]
8339-
pub struct AccountInfo<Nonce, AccountData> {
8340-
/// The number of transactions this account has sent.
8341-
pub nonce: Nonce,
8342-
/// The number of other modules that currently depend on this account's existence. The account
8343-
/// cannot be reaped until this is zero.
8344-
pub consumers: RefCount,
8345-
/// The number of other modules that allow this account to exist. The account may not be reaped
8346-
/// until this and `sufficients` are both zero.
8347-
pub providers: RefCount,
8348-
/// The number of modules that allow this account to exist for their own purposes only. The
8349-
/// account may not be reaped until this and `providers` are both zero.
8350-
pub sufficients: RefCount,
8351-
/// The additional data that belongs to this account. Used to store the balance(s) in a lot of
8352-
/// chains.
8353-
pub data: AccountData,
8354-
}
8251+
83558252
```
83568253

83578254
The `AccountInfo` structure includes the following components:
@@ -9365,8 +9262,7 @@ The [`XcmRouter`](https://paritytech.github.io/polkadot-sdk/master/pallet_xcm/pa
93659262
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.
93669263

93679264
```rust
9368-
pub type PriceForChildParachainDelivery =
9369-
ExponentialPrice<FeeAssetId, BaseDeliveryFee, TransactionByteFee, Dmp>;
9265+
93709266
```
93719267

93729268
For more details about XCM transport protocols, see the [XCM Channels](/develop/interoperability/xcm-channels/){target=\_blank} page.
@@ -10492,95 +10388,25 @@ The `xcm-emulator` provides macros for defining a mocked testing environment. Ch
1049210388
- **[`decl_test_relay_chains`](https://github.com/paritytech/polkadot-sdk/blob/polkadot-stable2506-2/cumulus/xcm/xcm-emulator/src/lib.rs#L361){target=\_blank}**: Defines runtime and configuration for the relay chains. Example:
1049310389

1049410390
```rust
10495-
decl_test_relay_chains! {
10496-
#[api_version(13)]
10497-
pub struct Westend {
10498-
genesis = genesis::genesis(),
10499-
on_init = (),
10500-
runtime = westend_runtime,
10501-
core = {
10502-
SovereignAccountOf: westend_runtime::xcm_config::LocationConverter,
10503-
},
10504-
pallets = {
10505-
XcmPallet: westend_runtime::XcmPallet,
10506-
Sudo: westend_runtime::Sudo,
10507-
Balances: westend_runtime::Balances,
10508-
Treasury: westend_runtime::Treasury,
10509-
AssetRate: westend_runtime::AssetRate,
10510-
Hrmp: westend_runtime::Hrmp,
10511-
Identity: westend_runtime::Identity,
10512-
IdentityMigrator: westend_runtime::IdentityMigrator,
10513-
}
10514-
},
10515-
}
10391+
1051610392
```
1051710393

1051810394
- **[`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:
1051910395

1052010396
```rust
10521-
decl_test_parachains! {
10522-
pub struct AssetHubWestend {
10523-
genesis = genesis::genesis(),
10524-
on_init = {
10525-
asset_hub_westend_runtime::AuraExt::on_initialize(1);
10526-
},
10527-
runtime = asset_hub_westend_runtime,
10528-
core = {
10529-
XcmpMessageHandler: asset_hub_westend_runtime::XcmpQueue,
10530-
LocationToAccountId: asset_hub_westend_runtime::xcm_config::LocationToAccountId,
10531-
ParachainInfo: asset_hub_westend_runtime::ParachainInfo,
10532-
MessageOrigin: cumulus_primitives_core::AggregateMessageOrigin,
10533-
DigestProvider: (),
10534-
},
10535-
pallets = {
10536-
PolkadotXcm: asset_hub_westend_runtime::PolkadotXcm,
10537-
Balances: asset_hub_westend_runtime::Balances,
10538-
Assets: asset_hub_westend_runtime::Assets,
10539-
ForeignAssets: asset_hub_westend_runtime::ForeignAssets,
10540-
PoolAssets: asset_hub_westend_runtime::PoolAssets,
10541-
AssetConversion: asset_hub_westend_runtime::AssetConversion,
10542-
SnowbridgeSystemFrontend: asset_hub_westend_runtime::SnowbridgeSystemFrontend,
10543-
Revive: asset_hub_westend_runtime::Revive,
10544-
}
10545-
},
10546-
}
10397+
1054710398
```
1054810399

1054910400
- **[`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:
1055010401

1055110402
```rust
10552-
decl_test_bridges! {
10553-
pub struct RococoWestendMockBridge {
10554-
source = BridgeHubRococoPara,
10555-
target = BridgeHubWestendPara,
10556-
handler = RococoWestendMessageHandler
10557-
},
10558-
pub struct WestendRococoMockBridge {
10559-
source = BridgeHubWestendPara,
10560-
target = BridgeHubRococoPara,
10561-
handler = WestendRococoMessageHandler
10562-
}
10563-
}
10403+
1056410404
```
1056510405

1056610406
- **[`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:
1056710407

1056810408
```rust
10569-
decl_test_networks! {
10570-
pub struct WestendMockNet {
10571-
relay_chain = Westend,
10572-
parachains = vec![
10573-
AssetHubWestend,
10574-
BridgeHubWestend,
10575-
CollectivesWestend,
10576-
CoretimeWestend,
10577-
PeopleWestend,
10578-
PenpalA,
10579-
PenpalB,
10580-
],
10581-
bridge = ()
10582-
},
10583-
}
10409+
1058410410
```
1058510411

1058610412
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](/parachains/customize-runtime/pallet-development/pallet-testing/){target=\_blank} article.

0 commit comments

Comments
 (0)