Skip to content

Moonbeam上预编译合约的概述

Precompiled Contracts Banner

概述

在Moonbeam上,预编译合约是拥有以太坊格式地址的原生Substrate代码,与其他智能合约一样能够可以使用以太坊API进行调用。预编译允许您直接调用Substrate runtime,其通常在Moonbeam的以太坊这端无法访问。

用于实施预编译的Substrate代码可以在EVM pallet中找到。EVM pallet包含了以太坊上的标准预编译以及一些不特定于以太坊的预编译。它也包含了通过通用Precompiles 特征创建和执行自定义预编译的能力。目前已经创建了好几个特定于Moonbeam的自定义预编译,您可以在Moonbeam代码库中找到。

以太坊预编译合约包含了带有大量计算的复杂功能,例如哈希和加密等。Moonbeam上自定义预编译合约提供对基于Substrate功能的访问,例如质押、治理、XCM相关函数等。

特定于Moonbeam的预编译可以通过以太坊API使用大家熟悉又简单易懂的Solidity接口来进行交互,它们最终被用于与底层Substrate接口进行交互。该流程如下图所示:

Precompiled Contracts Diagram

注意事项

在Moonbeam使用预编译合约时,可能会出现一些意想不到的后果。 请参阅安全注意事项 页面了解更多信息。

预编译合约地址

预编译合约是通过其地址并基于其原始网络来分类的。如果您将预编译地址转化至小数格式,并依据数值将其分类,则有以下几种类别:

以太坊主网预编译

合约 地址
ECRECOVER 0x0000000000000000000000000000000000000001
SHA256 0x0000000000000000000000000000000000000002
RIPEMD160 0x0000000000000000000000000000000000000003
Identity 0x0000000000000000000000000000000000000004
Modular Exponentiation 0x0000000000000000000000000000000000000005
BN128Add 0x0000000000000000000000000000000000000006
BN128Mul 0x0000000000000000000000000000000000000007
BN128Pairing 0x0000000000000000000000000000000000000008
Blake2 0x0000000000000000000000000000000000000009

非Moonbeam特定或以太坊预编译

合约 地址
SHA3FIPS256 0x0000000000000000000000000000000000000400
Dispatch 0x0000000000000000000000000000000000000401
ECRecoverPublicKey 0x0000000000000000000000000000000000000402

Moonbeam特定预编译

合约 地址
Parachain Staking 0x0000000000000000000000000000000000000800
Crowdloan Rewards 0x0000000000000000000000000000000000000801
ERC-20 Interface 0x0000000000000000000000000000000000000802
Democracy 0x0000000000000000000000000000000000000803
Xtokens 0x0000000000000000000000000000000000000804
Relay Encoder 0x0000000000000000000000000000000000000805
XCM Transactor 0x0000000000000000000000000000000000000806
Author Mapping 0x0000000000000000000000000000000000000807
Batch 0x0000000000000000000000000000000000000808
Randomness 0x0000000000000000000000000000000000000809
Call Permit 0x000000000000000000000000000000000000080a
XCM Utils 0x000000000000000000000000000000000000080C
Council Collective 0x000000000000000000000000000000000000080e
Technical Committee Collective 0x000000000000000000000000000000000000080f
Treasury Council Collective 0x0000000000000000000000000000000000000810
合约 地址
Parachain Staking 0x0000000000000000000000000000000000000800
Crowdloan Rewards 0x0000000000000000000000000000000000000801
ERC-20 Interface 0x0000000000000000000000000000000000000802
Democracy 0x0000000000000000000000000000000000000803
Xtokens 0x0000000000000000000000000000000000000804
Relay Encoder 0x0000000000000000000000000000000000000805
XCM Transactor 0x0000000000000000000000000000000000000806
Author Mapping 0x0000000000000000000000000000000000000807
Batch 0x0000000000000000000000000000000000000808
Randomness 0x0000000000000000000000000000000000000809
Call Permit 0x000000000000000000000000000000000000080a
XCM Utils 0x000000000000000000000000000000000000080C
Council Collective 0x000000000000000000000000000000000000080e
Technical Committee Collective 0x000000000000000000000000000000000000080f
Treasury Council Collective 0x0000000000000000000000000000000000000810
合约 地址
Parachain Staking 0x0000000000000000000000000000000000000800
Crowdloan Rewards 0x0000000000000000000000000000000000000801
ERC-20 Interface 0x0000000000000000000000000000000000000802
Democracy 0x0000000000000000000000000000000000000803
Xtokens 0x0000000000000000000000000000000000000804
Relay Encoder 0x0000000000000000000000000000000000000805
XCM Transactor Legacy 0x0000000000000000000000000000000000000806
Author Mapping 0x0000000000000000000000000000000000000807
Batch 0x0000000000000000000000000000000000000808
Randomness 0x0000000000000000000000000000000000000809
Call Permit 0x000000000000000000000000000000000000080a
Proxy 0x000000000000000000000000000000000000080b
XCM Utils 0x000000000000000000000000000000000000080C
XCM Transactor 0x000000000000000000000000000000000000080d
Council Collective 0x000000000000000000000000000000000000080e
Technical Committee Collective 0x000000000000000000000000000000000000080f
Treasury Council Collective 0x0000000000000000000000000000000000000810