Skip to main content
Version: 4.0

Chain Environment Types


If you write a contract for a chain that deviates from the default Substrate types, you have to make sure to configure that chain's Environment for your contract!

ink! defines a trait Environment and also a default implementation of that trait ‒ DefaultEnvironment.

These are the types that ink! uses, if no explicit steps are taken:

/// The fundamental types of the default configuration.
#[derive(Debug, Clone, PartialEq, Eq)]
#[cfg_attr(feature = "std", derive(TypeInfo))]
pub enum DefaultEnvironment {}

impl Environment for DefaultEnvironment {
const MAX_EVENT_TOPICS: usize = 4;

type AccountId = ink_primitives::AccountId;
type Balance = u128;
type Hash = ink_primitives::Hash;
type Timestamp = u64;
type BlockNumber = u32;
type ChainExtension = NoChainExtension;

The context here is that you can use ink! on any blockchain that was built with the Substrate framework and includes the pallet-contracts module.

Chains built on Substrate can decide on their own which types they want to use for e.g. the chain's block number or account id's. For example, chains that intend to be compatible to Ethereum typically use the same type as Ethereum for their AccountId.

Most Substrate chains stay with the default Substrate types though and ink! just uses those by default as well. It is possible to configure a different environment in the contract macro (documentation here) though:

#[ink::contract(env = MyCustomTypes)]