Smart Contracts
R5 smart contracts are fully compatible with the EVM and can be developed using popular languages such as Solidity and Vyper. This document provides technical details on how to write, compile and deploy contracts on the R5 network, as well as an example contract to get you started.
Key Features
EVM Compatibility: R5 smart contracts run on a standard EVM, ensuring that bytecode produced by Solidity or Vyper compilers executes consistently. You can use familiar development tools and frameworks without modification.
Language Support: Develop contracts using Solidity or Vyper. The resulting bytecode is executed by the R5 Virtual Machine, supporting all EVM opcodes and gas calculations according to the R5 configuration.
Efficient Deployment: The R5 network provides a stable environment for deploying contracts. Once deployed, contracts can be interacted with using standard JSON‑RPC endpoints.
Full Control: Developers have access to a rich set of debugging and profiling tools that help optimise contract execution and monitor gas usage.
Example Smart Contract
Below is a simple Solidity contract that demonstrates a basic token implementation on the R5 network. This example uses Solidity version 0.8.x and includes standard ERC‑20 functions, such as transferring tokens and managing allowances.
Explanation
Deployment: Deploy the contract by specifying an initial supply. The total supply is assigned to the deployer's address at deployment.
Standard Operations: The contract includes basic token transfer functions (
transfer
), approval and allowance management (approve
andtransferFrom
), and events to log transfers and approvals.EVM Execution: The contract compiles to EVM bytecode and is executed by the R5 Virtual Machine, ensuring that all operations such as gas calculations and state changes follow the R5 network’s parameters.
Getting Started
Compilation and Deployment: Use a Solidity or Vyper compiler (compatible with version 0.8.x or the version required by your project) along with tools like Remix, Truffle, or Hardhat to compile your contract. Deploy it on the R5 network using your preferred method (e.g. the R5 JS Console or deployment scripts).
Interacting with Contracts: Once deployed, interact with your contract using JSON‑RPC endpoints provided by the R5 node. For example, call functions to transfer tokens or check an account's balance.
Testing and Debugging: Leverage R5’s built-in debugging tools and the JS Console to trace transactions and monitor gas usage. These tools help ensure your contracts execute as expected in the R5 environment.
Optimisation: Use profiling tools to optimise contract code and gas efficiency. Detailed logs and performance metrics are available to help refine your smart contract operations.
Last updated