Web3 Core OASIS
OASIS Provider Web3CoreOASIS is created to provide Avatar and Holon entities management, such as Save, Load, and Delete operations by using EVM-compatible blockchains.
Currently, OASIS supports the following EVM-compatible blockchains:
EthereumOASIS.
ArbitrumOASIS.
PolygonOASIS.
RootstockOASIS.
EthereumOASIS and ArbitrumOASIS are developed independently, with their own smart contracts and code base. PolygonOASIS and RootstockOASIS are based on Web3CoreOASIS, using its code base, new, efficient, and modern Web3CoreOASIS smart contract.
This approach helps develop a single code base that can be shared and used by multiple providers, making the development process faster.
Web3CoreOASIS Smart Contract
Web3CoreOASIS Smart Contract comes with a single data entity, interface, and implementation.
Data Entity
Data entity is an object that stores Avatar or Holon data efficiently.
struct EntityOASIS {
uint256 EntityId;
bytes32 ExternalId;
bytes Info;
}EntityId- Unique integer-based identification value.ExternalId- Uniquebytes32based identification (GUID, can be represented as string) value of Avatar or Holon.Info- JSON string containing Avatar and Holon data.
Web3CoreOASIS
Web3CoreOASIS class is a Web3 client, used to call smart contract functions by making RPC calls to the chain.
Web3CoreOASISBaseProvider
Web3CoreOASISBaseProvider class provides an implementation for IOASISStorageProvider interface, by using Web3CoreOASIS.
Hardhat Usage
Configuration
The Hardhat configuration is set up in hardhat.config.cjs, supporting local development, Rootstock, and Polygon networks. The configuration includes compiler settings, network endpoints, and necessary plugins.
To configure Hardhat and include support for the Polygon and Rootstock networks, follow these steps:
Install Hardhat and Dependencies:
Hardhat Configuration:
Create or update the
hardhat.config.cjsfile with the following content:Environment Variables:
Store your private key in a
.envfile:Load environment variables in your
hardhat.config.cjsfile:
Setting Up Private Keys and Addresses
To interact with the blockchain, you need a private key and an address. Here’s how you can get them:
Generate a New Ethereum Address:
Use MetaMask or any other Ethereum wallet to generate a new address.
Get Your Private Key:
Export your private key from MetaMask:
Open MetaMask and click on the account icon.
Select "Account Details" and then "Export Private Key".
Enter your password to reveal the private key.
Store Your Private Key:
Save your private key in a
.envfile as shown above.
Faucets for Test Networks
To get test ETH or tokens on the test networks, use the following faucets:
Polygon Mumbai Faucet: faucet.polygon.technology
Rootstock Faucet: faucet.rootstock.io
Additional Resources
For a guide on porting Ethereum dApps to Rootstock, refer to this tutorial.
Obtaining Etherscan API Key
To interact with Etherscan for verifying and publishing your smart contracts, you need to obtain an API key from Etherscan. Follow these steps to get your Etherscan API key:
Sign Up on Etherscan:
Visit Etherscan and sign up for a free account if you don't already have one.
Login to Your Account:
After signing up, log in to your Etherscan account.
Access API Keys:
Once logged in, navigate to the API Keys section from your account dashboard.
Create a New API Key:
Click on "Add" to create a new API key.
Provide a name for your API key (e.g., "Web3CoreOASIS") and click "Create New API Key Token".
Copy Your API Key:
After the key is generated, copy it for use in your Hardhat configuration.
Store Your API Key Securely:
Save the API key in a secure place. It’s recommended to store it in an environment variable in your
.envfile:
Use Your API Key in Hardhat:
Update your
hardhat.config.cjsfile to include the Etherscan API key for contract verification:
Local Network
Start a local Hardhat node with:
Deployment Script
Deploy the smart contract using:
Testing
Run unit tests using:
Code Style Rules
Code style rules for the project are enforced using solhint, which ensures consistent formatting and best practices for Solidity code. The standard styling rules include:
Indentation: Use 4 spaces for indentation.
Quotes: Use double quotes for string literals.
Line Length: Limit lines to 120 characters.
Function Visibility: Explicitly define visibility for all functions.
Error Handling: Use
require,assert, andrevertfor error handling.Naming Conventions: Follow camelCase for functions and variables, and PascalCase for contract names.
Using Solhint
solhint is a linter for Solidity code that checks for style violations and potential issues. To use solhint in your project:
Install Solhint:
Create a Solhint Configuration File:
Create a
.solhint.jsonfile in the root of your project with the following content:Lint Your Solidity Code:
Run
solhinton your Solidity files to check for style violations:
These steps ensure your Solidity code adheres to the specified style guidelines, improving readability and maintainability.
Deploy and Test
Deployment
A bash script deploy.sh automates the deployment process. It accepts the network as an argument and optionally runs tests after deployment.
Unit Tests
Unit tests are written using the Hardhat framework and Chai assertion library. They include tests for creating avatars, loading avatars, and ensuring data integrity.
Performance Tests
Performance tests measure the execution time and gas usage of contract functions.
Gas Estimate Tests
Gas estimate tests ensure that contract functions are optimized for gas usage.
Last updated