The Contracts pallet provides the ability for the runtime to deploy and execute WebAssembly (WASM) smart contracts
The Contracts pallet depends on a Wasm sandboxing interface defining the Wasm execution engine available within the runtime.
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
Balancethat normal accounts have, a contract account also has an associated contract code and some persistent contract storage.
- Store the Wasm contract on the blockchain.
- Instantiate a new account, with new storage, associated with that Wasm contract.
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.
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.
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 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.