diff --git a/docs/basics/precompiles.md b/docs/basics/precompiles.md new file mode 100644 index 0000000000..168687702b --- /dev/null +++ b/docs/basics/precompiles.md @@ -0,0 +1,28 @@ +--- +title: Precompiles +slug: /basics/precompiles +hide_title: true +--- + +![Precompiles Title Picture](/img/title/precompiles.svg) + +# Precompiles + +[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 + +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",