Energy Web Documentation
  • Energy Web Ecosystem
  • Launchpad by Energy Web
  • EWC Validator Documentation
  • Community Ressources
  • Legacy documentation
  • Welcome to Energy Web
  • Glossary
  • Solutions 2023
    • ↔️Data Exchange
      • Data Exchange Overview
      • Data Exchange Architecture
      • Use Cases and Refrence Implementations
        • Digital Spine for Electricity Markets
          • Digital Spine Integration Client Deployment Guide - from Azure marketplace
        • E-Mobility Management
    • 🔌Open Charging Network
      • Create and Manage an OCN Identity
      • Connect an OCPI/OCN Party to a Node
        • 1. Make your backend service OCN-ready
        • 2. Select an OCN Node and register in OCN Registry
        • 3. Manage your Whitelist and Blacklist
        • 4. Connect your service to an OCN Node
      • Run an OCN Node
      • Use the OCN Service Interface
        • Offer an OCN Service
        • Sign up for an OCN Service
      • Develop on the Test Network
      • Develop on the Production Network
      • Open Source Development
        • Maturity Model, Feature Roadmap and Releases
        • Developer Community Calls
      • E-Mobility Dashboard v0.1
  • EW-DOS Technology Components 2023
    • EW-DOS Overview
    • Worker Nodes
      • Worker Node Process Diagrams
      • Worker Node Architecture
      • Worker Node Guides
        • Deploy Worker Nodes
        • Customize Worker Logic
    • Identity and Access Management (IAM)
      • IAM Guides
        • Implement an SSI Hub instance
        • Verifiable Credential API
        • Sign-In with Ethereum
        • Using Switchboard
          • Switchboard Transaction Cost Estimates
      • IAM Patterns
        • Assets as Ownable Smart Contracts
        • Credential Lifecycle
        • Credential Metadata
        • SSI Credential Governance using ENS Domains
      • IAM Libraries
      • SSI Hub
      • Switchboard Application
    • Decentralized Data Hub (DDHub)
      • DDHub Message Broker
      • DDHub Client Gateway
      • DDHub Patterns
        • Channels and Topics
      • DDHub Guides
    • Green Proofs Contracts
    • Energy Web X
    • The Energy Web Chain
      • EWC Overview
      • System Architecture
        • Proof-of-Authority Consensus Mechanism
        • System Contracts
          • Name Registry
          • Holding Contract
          • Block Reward Contract
          • Validator-Set Contracts
        • Validator Node Architecture
      • Energy Web Block Explorer
      • Validator Node Installation Specifications
        • Volta Test Network: Validator Node Installation
      • Energy Web Chain Governance
      • EWC Guides and Tutorials
        • Getting started with Energy Web Chain
        • Developing on the Volta Test Network and Main Network (Energy Web Chain)
        • Run a Local RPC Node
          • Run RPC Node using Nethermind client
        • Deploy a Smart Contract on Volta with Remix
        • Interacting with Smart Contracts in EW-DOS
        • Set up MetaMask to interact with Energy Web Chain
        • Using the Ethereum Name Service
        • Using Oracles
      • Energy Web Token (EWT)
  • 🧠Foundational Concepts
    • Open-Source Software
    • Scaling Access to Grid Flexibility
    • Facilitating Clean Energy Purchases
    • Ethereum
      • Transactions and Transaction Costs
    • Self-Sovereign-Identity
      • Self-Sovereign Use Case Interaction
    • Cryptocurrency Wallets
      • Software cryptocurrency wallets
        • Metamask
        • Mycrypto wallet
      • Hardware cryptocurrency wallets
      • Hierarchical Deterministic (HD) Wallets
Powered by GitBook
On this page
  • API Client Libraries
  • 1. Instantiate a Provider
  • 2. Instantiate a Contract
  • 2. Implement Contract Methods
  • EW-DOS Smart Contracts
Export as PDF
  1. EW-DOS Technology Components 2023
  2. The Energy Web Chain
  3. EWC Guides and Tutorials

Interacting with Smart Contracts in EW-DOS

Using smart contracts on the Ethereum Virtual Machine

PreviousDeploy a Smart Contract on Volta with RemixNextSet up MetaMask to interact with Energy Web Chain

Last updated 2 years ago

EW-DOS utility layer packages and SDKs interact with . To do this, they use API Client Libraries to connect to the blockchain and create instances of smart contracts to access their public functions.

If you're not familiar with what a smart contract is, you can read Ethereum's introduction to smart contracts .

Below we provide an overview of API Client libraries and a some code examples. Note that exact implementation varies in each package or SDK, but the fundamental concepts remain the same.

API Client Libraries

You can interact with smart contracts (i.e. call their public read and write functions) on the the Energy Web Chain and the Volta Test Network using any Ethereum API client library. Client libraries allow you to connect to and interact with the blockchain network. You can read about all the functionalities of Ethereum API client libraries in the Ethereum documentation .

The most popular JavaScript libraries for interacting with Ethereum networks are and . EW-DOS uses ethers.js, so below we will provide ethers.js examples, however concepts will be similar among different client libraries.

When interacting with a contract, you use a library to first create a Provider, which is a connection the blockchain. You then use the provider to create an instance of the smart contract that you want to interact with. Once this instance is created, you can call the public methods that are exposed in the smart contract.

1. Instantiate a Provider

A provider is a connection to the blockchain. It gives you an interface to interact with the network. To create a , you will need the JSON RPC Url. To create an , you will need the path local IPC filename (this is only available in node.js).

You can see the full ethers.js documentation on Providers .

import { providers, Signer, utils, errors, Wallet } from "ethers";
const { JsonRpcProvider } = providers;

this._provider = new JsonRpcProvider({ url: rpcUrl });

See source code

2. Instantiate a Contract

To create a new instance of a contract that is already deployed on the blockchain, you need three pieces of information:

  1. The contract's ABI- the ABI (Application Binary Interface). The ABI is a JSON object that provides the interface to your smart contract. It defines the contract's constructor, events and the behavior of its public functions. The contract's ABI is generated with the smart contract is compiled.

  2. The contract's address - every smart contract has an address when it is deployed to the blockchain. You can deploy the same contract on multiple blockchains, but each contract will have a different address.

  3. The provider

//pass in the smart contract address, smart contract ABI, provider:
this._contract = new Contract(settings.address, this.settings.abi, this._provider);

2. Implement Contract Methods

The Contract method returns a new instance of that contract at the address passed in. Now that we have an instance of this contract, we can interact with its public methods:

    try {
      valid = await this._contract.validDelegate(identityAddress, bytesType, delegateAddress);
    } catch (error) {
      throw new Error(error);
    }

EW-DOS Smart Contracts

Smart Contracts

Link to Source Code

IAM Smart Contracts

You can see the ethers.js documentation **** for creating a new instance of a deployed Contract .

See source code

See source code

Smart Contracts

System Contracts

Energy Web

Contracts

For a tutorial on how to deploy a smart contract on the Volta Test Network or Energy Web Main Network, go .

here
here
here
here
Deploy a Smart Contract on Volta with Remix
here
here
ethers.js
web3.js
JSONRpcProvider
IPCProvider
here
here
smart contracts that are deployed on the Energy Web Chain
Origin
https://github.com/energywebfoundation/iam-contracts
https://github.com/energywebfoundation/origin/tree/master/packages/traceability/issuer/contracts
https://github.com/energywebfoundation/volta-system-contracts
System Contracts
https://github.com/energywebfoundation/ewc-system-contracts
Staking
https://github.com/energywebfoundation/staking-contracts
Volta