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 - Unique bytes32 based 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:

  1. Install Hardhat and Dependencies:

  2. Hardhat Configuration:

    Create or update the hardhat.config.cjs file with the following content:

  3. Environment Variables:

    Store your private key in a .env file:

    Load environment variables in your hardhat.config.cjs file:

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:

  1. Generate a New Ethereum Address:

    Use MetaMask or any other Ethereum wallet to generate a new address.

  2. 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.

  3. Store Your Private Key:

    Save your private key in a .env file as shown above.

Faucets for Test Networks

To get test ETH or tokens on the test networks, use the following faucets:

Additional Resources

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:

  1. Sign Up on Etherscan:

  2. Login to Your Account:

    • After signing up, log in to your Etherscan account.

  3. Access API Keys:

  4. 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".

  5. Copy Your API Key:

    • After the key is generated, copy it for use in your Hardhat configuration.

  6. 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 .env file:

  7. Use Your API Key in Hardhat:

    • Update your hardhat.config.cjs file 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, and revert for 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:

  1. Install Solhint:

  2. Create a Solhint Configuration File:

    Create a .solhint.json file in the root of your project with the following content:

  3. Lint Your Solidity Code:

    Run solhint on 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