From a16231a22a5c7c279de064a65b050853e293a904 Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Tue, 15 Jul 2025 18:43:59 +0200 Subject: [PATCH 1/2] feat: precompiles --- docs/basics/precompiles.md | 31 +++++++++++++++++++++++++++++++ sidebars.js | 1 + 2 files changed, 32 insertions(+) create mode 100644 docs/basics/precompiles.md diff --git a/docs/basics/precompiles.md b/docs/basics/precompiles.md new file mode 100644 index 0000000000..fe20ac781c --- /dev/null +++ b/docs/basics/precompiles.md @@ -0,0 +1,31 @@ +--- +title: Precompiles +slug: /basics/precompiles +hide_title: true +--- + +![Precompiles Title Picture](/img/title/precompiles.svg) + +# Precompiles + +Precompiles are pre-defined functions implemented directly into the blockchain's runtime, unlike smart +contracts that execute within the virtual machine. This makes heavy operations cheaper and also turns +precompiles into adapters that let smart contracts call into chain features. Precompiles exist at +predetermined addresses and offer optimized performance with lower gas costs than equivalent contract +implementations. + +## Using Precompiles in ink! Contracts + +In ink!, precompiles are called exactly like any other contract using the same [cross-contract calling mechanisms](./cross-contract-calling.md). You simply target the precompile's predetermined address instead of a deployed contract address. + +## Discovering Chains Precompiles + +To find available precompiles on a Polkadot SDK chain, check the runtime configuration in the `pallet-revive` section for the `Precompiles` type definition. + +```rust +impl pallet_revive::Config for Runtime { + ... + type Precompiles = MyChainPrecompiles; + ... +} +``` \ No newline at end of file diff --git a/sidebars.js b/sidebars.js index 2333909356..0b25dbdce4 100644 --- a/sidebars.js +++ b/sidebars.js @@ -27,6 +27,7 @@ module.exports = { "basics/trait-definitions", "basics/gas", "basics/cross-contract-calling", + "basics/precompiles", "basics/upgradeability", "basics/env-functions", "basics/environment", From 4326abe6d69ffbb3519373fb63a7e6edeed8d457 Mon Sep 17 00:00:00 2001 From: Daanvdplas Date: Tue, 15 Jul 2025 19:28:36 +0200 Subject: [PATCH 2/2] chore: add link --- docs/basics/precompiles.md | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/docs/basics/precompiles.md b/docs/basics/precompiles.md index fe20ac781c..168687702b 100644 --- a/docs/basics/precompiles.md +++ b/docs/basics/precompiles.md @@ -8,10 +8,7 @@ hide_title: true # Precompiles -Precompiles are pre-defined functions implemented directly into the blockchain's runtime, unlike smart -contracts that execute within the virtual machine. This makes heavy operations cheaper and also turns -precompiles into adapters that let smart contracts call into chain features. Precompiles exist at -predetermined addresses and offer optimized performance with lower gas costs than equivalent contract +[Precompiles](https://docs.polkadot.com/develop/smart-contracts/precompiles/) are pre-defined functions implemented directly into the blockchain's runtime, unlike smart contracts that execute within the virtual machine. This makes heavy operations cheaper and also turns precompiles into adapters that let smart contracts call into chain features. Precompiles exist at predetermined addresses and offer optimized performance with lower gas costs than equivalent contract implementations. ## Using Precompiles in ink! Contracts