Skip to content

Network Specific ENS Lookup#228

Merged
dOrgJelli merged 19 commits intoprealpha-devfrom
network-specific-ens-lookup
Apr 12, 2021
Merged

Network Specific ENS Lookup#228
dOrgJelli merged 19 commits intoprealpha-devfrom
network-specific-ens-lookup

Conversation

@dOrgJelli
Copy link
Copy Markdown
Contributor

@dOrgJelli dOrgJelli commented Mar 19, 2021

Notable Changes

Ethereum Plugin

Constructor

The EthereumPlugin can now be constructed with multiple network connections like so:

import { ethereumPlugin } from "@web3api/ethereum-plugin-js";
import { Wallet } from "ethers";

const client = new Web3ApiClient({
  redirects: [
    {
      from: "ens/ethereum.web3api.eth",
      to: ethereumPlugin({
        mainnet: {
          provider: window.ethereum
        },
        rinkeby: {
          signer: new Wallet("mnemonic")
        },
        testnet: {
          provider: "http://localhost:8080
        },
        // If not specified, mainnet is used
        defaultNetwork: "rinkeby"
      })
    }
  ]
})

If no provider is provided, the name of the network (ex: "rinkeby" above) is used to get a default provider from ethers.js.

Connection Class

Multiple network connections is made possible by abstracting away the concept of a network connection into the Connection class.

Schema

The EthereumPlugin's schema has been updated to allow for custom network configurations to be specified. These configuration options are used to select which network connection you'd like to transact with.

type Query {
  callView(
    address: String!
    method: String!
    args: [String!]
    connection: Connection
  ): String!
}

type Mutation {
  sendTransaction(
    address: String!
    method: String!
    args: [String!]
    connection: Connection
  ): String!

  deployContract(
    abi: String!
    bytecode: String!
    args: [String!]
    connection: Connection
  ): String!
}

type Connection {
  node: String
  networkNameOrChainId: String
}

ENS Plugin

The EnsPlugin has been updated to allow for network names in the URI's path like so:

w3://ens/testnet/simplestorage.eth
w3://ens/rinkeby/other.web3api.eth

If no network is specified, mainnet is used.

SimpleStorage Web3API Demo

The SimpleStorage Web3API demo has been updated in the following ways:

  1. The e2e.json query recipe now specifies /ens/testnet/simplestorage.eth for the API it is connecting to.
  2. In the SimpleStorage.eth's schema, it now supports configuring what Ethereum connection to be used. For example:
#import { Query, Connection } into Ethereum from "w3://ens/ethereum.web3api.eth"

type Query {
  getData(
    address: String!
    connection: Ethereum_Connection
  ): Int!
}

If nothing is specified, the EthereumPlugin's defaultProvider is used.

NOTE: in the future nested configuration values like this will be configured through Web3API env variables (see: #140)
3. The e2e.json queries set the query method's connection to testnet. Otherwise, the Web3API would try and send transactions to mainnet.

@dOrgJelli dOrgJelli changed the title [Draft] Network Specific ENS Lookup Network Specific ENS Lookup Mar 30, 2021
@dOrgJelli dOrgJelli requested review from krisbitney and namesty April 10, 2021 04:12
Copy link
Copy Markdown
Collaborator

@namesty namesty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noted we cannot have more than one connection to the same network. I don't know if this is something we should allow anyways

Comment thread packages/js/plugins/ethereum/src/Connection.ts
@dOrgJelli
Copy link
Copy Markdown
Contributor Author

I noted we cannot have more than one connection to the same network. I don't know if this is something we should allow anyways

Hmmm interesting... I don't think this is a use-case we need to worry about since current wallets don't support this anyway. The most I've seen done in relation to this is having multiple fallback endpoints for a single network (ethersjs does this). I've never seen a library support multiple providers for a single network. How would we differentiate between them?

Maybe an interface like this may make sense?

connections: {
  mainnetA: {
    network: "mainnet",
    provider: ...
  },
  mainnetB: {
    network: "mainnet",
    provider: ...
  }
}

@dOrgJelli dOrgJelli merged commit b9dc12c into prealpha-dev Apr 12, 2021
@dOrgJelli dOrgJelli deleted the network-specific-ens-lookup branch May 24, 2021 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants