Contracts Pallet

Overview

The Contracts pallet provides the ability for the runtime to deploy and execute WebAssembly (WASM) smart contracts

Description

Execution engine

The Contracts pallet depends on a Wasm sandboxing interface defining the Wasm execution engine available within the runtime.

Features

Account Based

The Contracts pallet uses an account-based system similar to many existing smart contract platforms. To the Glitch runtime, contract accounts are just like normal user accounts; however, in addition to AccountID and Balance that normal accounts have, a contract account also has an associated contract code and some persistent contract storage.

Two-step deployment

  • Store the Wasm contract on the blockchain.

  • Instantiate a new account, with new storage, associated with that Wasm contract.

Contract Calls

Calls to contracts can alter the storage of the contract, create new contracts, and call other contracts. The Contracts pallet also enables you to make asynchronous calls directly to those runtime functions on behalf of the contract's account.

Sandboxed

The Contracts pallet is intended to be used by any user on a public network. This means that contracts only have the ability to directly modify their own storage. To provide safety to the underlying blockchain state, the Contracts pallet enables revertible transactions, which roll back any changes to the storage by contract calls that do not complete successfully.

Gas

Contract calls are charged a gas fee to limit the amount of computational resources a transaction can use. When forming a contract transaction, a gas limit is specified. As the contract executes, gas is incrementally used up depending on the complexity of the computation. If the gas limit is reached before the contract execution completes, the transaction fails, contract storage is reverted, and the gas fee is not returned to the user. If the contract execution completes with the remaining gas, it is returned to the user at the end of the transaction.

Storage Rent

Storage rent limits the footprint that a contract can have on the blockchain's storage. A contract account is charged proportionally to the amount of storage its account uses.

Contracts Pallet vs. EVM pallet

Contract Pallet

EVM

Execution engine

The Contracts pallet depends on a Wasm sandboxing interface defining the Wasm execution engine available within the runtime.

The EVM pallet uses SputnikVM as the underlying EVM engine.

Storage fees

The Contracts pallet charges for storage fees through storage rent which ensures that any data that persists on the blockchain is appropriately charged for those resources.

The EVM charges for storage fees only at the time of storage. This one-time cost results in some permanent amount of storage being used on the blockchain

Contract creation

  • Store the Wasm contract on the blockchain.

  • Instantiate a new account, with new storage, associated with that Wasm contract.

  • There are a separate set of accounts managed by the EVM pallet.

  • Glitch based accounts can call the EVM pallet to deposit or withdraw balance from the Glitch base-currency into a different balance managed and used by the EVM pallet.

Last updated