EVM (General)
Overview
The Ethereum Virtual Machine (EVM) is the runtime environment for smart contracts, supporting compatibility with Ethereum-based decentralized applications (dApps). ENI is an EVM-compatible blockchain. ENI’s parallelized EVM ensures high performance and efficiency.
Here are some key points about the EVM:
Turing Completeness: The EVM is Turing complete, meaning it can execute any computable function. This allows developers to write complex smart contracts.
Gas: Transactions and contract executions on EVM-compatible networks consume gas. Gas is a unit of measure for computational work, and users pay for gas on the ENI network using ueni. Gas ensures that malicious or inefficient code does not overload the network.
Bytecode Execution: Smart contracts are compiled into bytecode (low-level, machine-readable instructions) and deployed to EVM-compatible networks. The EVM executes this bytecode.
Smart Contract Languages
The two most popular languages for developing smart contracts on the EVM are Solidity and Vyper.
Solidity
An object-oriented, high-level language for implementing smart contracts.
A curly-brace language most heavily influenced by C++.
Statically typed (variable types are known at compile time).
Supports:
Inheritance (can extend other contracts).
Libraries (reusable code can be created and called from different contracts—similar to static functions in static classes in other object-oriented programming languages).
Complex user-defined types.
Solidity Contract Example
Vyper
A Pythonic programming language.
Strong typing.
Small and understandable compiler code.
Efficient bytecode generation.
Deliberately has fewer features than Solidity with the aim of making contracts more secure and easier to audit. Vyper does not support:
Modifiers
Inheritance
Inline assembly
Function overloading
Operator overloading
Recursive calling
Infinite-length loops
Binary fixed points
Example Vyper Contract
Deploying EVM Contracts on ENI
Since ENI is an EVM-compatible chain, existing EVM tools such as Hardhat, Foundry Forge, or others can be reused.
In this example, we will use the Foundry tools.
Install Foundry tools by following the installation guide.
Create a new project by following the new project guide.
Also, ensure you have a wallet on the ENI network.
After the project is created, adjust the contract code by adding a getCount function as shown below:
And update the test code to the following:
Run the tests with the following command:
If the tests pass, deploy the contract to the ENI chain using the following command:
Where $ENI_NODE_URI is the URI of the ENI node, and $MNEMONIC is the mnemonic phrase of the account deploying the contract. If you are running a local ENI node, the address will be http://localhost:8545; otherwise, you can obtain the evm_rpc URL from the registry. If the deployment is successful, you will see the EVM contract address in the output.
Let’s query the contract using the cast command:
This command should return 0, the initial value of the counter.
Now, use the cast command to call the increment function:
If the command succeeds, you will receive the transaction hash and other information.
Now call the getCount function again; this time it should return 1.
Calling the Contract from a JS Client
To call the contract from a frontend, you can use ethers, for example:
Last updated