Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#189 Predeployed Contracts functionality #218

Merged
merged 6 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
** xref:guides/async_backing.adoc[Async Backing]
* EVM Template Guides
** xref:guides/contract_migration.adoc[Contract Migration]
** xref:guides/predeployed_contracts.adoc[Predeployed Contracts]
* Runtimes
** xref:runtimes/generic.adoc[Generic Runtime]
* Runtime Descriptions
Expand Down
51 changes: 51 additions & 0 deletions docs/modules/ROOT/pages/guides/predeployed_contracts.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
:source-highlighter: highlight.js
:highlightjs-languages: rust
:github-icon: pass:[<svg class="icon"><use href="#github-icon"/></svg>]

= Predeployed Contracts:

To enable some bleeding-edge features that EVM provides (like pay gas with any tokens), we have developed an ability to deploy contracts in genesis config. Initially it was done to deploy Entrypoint contract only, but we have supported this functionality for any contract with some limitations.

== How to use:

=== Step 1: Compiling your contracts

Currently we are supporting contracts that are compiled with Forge or Hardhat. If you want any other tool to be supported, consider creating an issue and attach and example of compiled contract.

Here are compilation guides:

* link:https://hardhat.org/hardhat-runner/docs/guides/compile-contracts[Hardhat]
* link:https://book.getfoundry.sh/reference/forge/forge-build[Forge]

When you have compiled the contracts, take the resulting JSON for your contract and save into a single directory for the future deployment.

=== Step 2: Creating the configuration

In the directory where you have saved the contracts, create a file name "contracts.json". In this file you should store an array of contract metadata, that contains filename of the artifact and the address where you want this contract to be deployed to. So, it should like like this:

```json
[
{
"address": "0x81ead4918134AE386dbd04346216E20AB8F822C4",
"filename": "Entrypoint.json"
}
]
```

You can take as an example a file in our EVM template in path `contracts/contracts.json`.

=== Step 3: Building the chainspec

During the step when you generate a chainspec pass the parameter `--predeployed-contracts` with a path to the directory where you have stored the contract artifacts and the configuration:

```bash
./target/release/parachain-template-node build-spec --disable-default-bootnode --predeployed-contracts=<path_to_dir> > plain-parachain-chainspec.json
```

== Exclude any contracts from genesis config

If you do not want any contract to be predeployed, you can use the `--no-predeployed-contracts` option when you are generating a plain chainspec. With this flag set you will receive a pristine chainspec without any additional smartcontracts deployed.

== Limitations

* Contructors are not executed at the moment. So if your contract needs any initialization, consider deploying it as usual.
2 changes: 2 additions & 0 deletions evm-template/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions evm-template/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ repository = "https://github.com/OpenZeppelin/polkadot-runtime-template"
clap = { version = "4.5.3", features = [ "derive" ] }
color-print = "0.3.4"
futures = "0.3.28"
hex = "0.4.3"
hex-literal = "0.4.1"
jsonrpsee = { version = "0.22", features = [ "server" ] }
log = { version = "0.4.20", default-features = false }
Expand All @@ -22,6 +23,7 @@ parity-scale-codec = { version = "3.0.0", default-features = false, features = [
] }
scale-info = { version = "2.10.0", default-features = false }
serde = { version = "1.0.188", default-features = false }
serde_derive = { version = "1.0.188", default-features = false }
serde_json = "1.0.108"
smallvec = "1.11.0"

Expand Down
Loading
Loading