Creating Smart Contracts
A smart contract is an immutable program consisting of a set of logic (state variables, functions, event handlers, etc.) or rules that can be deployed, stored, and accessed on a distributed ledger technology such as Hedera. The functions contained within a smart contract can update and manage the state of the contract and read data from the deployed contract. They may also create and call other smart contracts functions on the network. Smart contracts are secure, tamper-proof, and transparent, offering a new level of trust and efficiency.
Hedera supports any language that compiles to the Ethereum Mainnet. This includes Solidity and Vyper. These programming languages compile code and produce bytecode that the Ethereum Virtual Machine (EVM) can interpret and understand.
To learn more about the Solidity programming language, check out the documentation maintained by the Solidity team here.
To learn more about Vyper, check out the documentation maintained by the Vyper team here.
In addition, many tools are available to write and compile smart contracts, including the popular Remix IDE and Hardhat. The Remix IDE is a user-friendly platform that allows you to easily write and compile your smart contracts and perform other tasks such as debugging and testing. Using these tools, you can create powerful and secure smart contracts that can be used for various purposes, from simple token transfers to complex financial instruments.
Example
The following is a very simple example of a smart contract written in the Solidity programming language. The smart contract defines the owner
and message
state variables, along with functions like set_message
(which modifies state details by writing) and get_message
(which reads state details).
Things you should consider when creating a contract
Automatic Token Associations
An auto association slot is one or more slots you approve that allow tokens to be sent to your contract without explicit authorization for each token type. If this property is not set, you must approve each token before it is transferred to the contract for the transfer to be successful via the TokenAssociateTransaction
in the SDKs. Learn more about auto-token associations here.
This functionality is exclusively accessible when configuring a ContractCreateTransaction
API through the Hedera SDKs. If you are deploying a contract on Hedera using EVM tools such as Hardhat and the Hedera JSON RPC Relay, please note that this property cannot be configured, as EVM tools lack compatibility with Hedera's unique features.
Admin Key
Contracts have the option to have an admin key. This concept is native to Hedera contracts and allows the contract account properties to be updated. Note that this does not impact the contract bytecode and does not relate to upgradability. If the admin key is not set, you will not be able to update the following Hedera native properties (noted in ContractUpdateTransactionBody protobuf) for your contract once it is deployed:
You cannot set the admin key field if you deploy a contract via tools like Hardhat. This field can be set if desired by deploying a contract using one of the Hedera SDKs.
Max Contract Storage Size
Contracts on Hedera have a storage size limit of 16,384,000 key value pairs (~100MB).
Rent
While rent is not enabled for contracts deployed on Hedera today, you will want to be familiar with the concept of rent, as it may potentially impact the costs of maintaining your contract state on the network. Please refer to the Smart Contract Rent documentation here.
Transaction and Gas Fees
There are Hedera transaction fees and EVM fees associated with deploying a contract. To view the list of base fees, check out the fees page here and the fee estimator calculator here.
Smart Contract FAQs
Last updated