@polywrap/ethereum-plugin-js
TypeScript icon, indicating that this package has built-in type declarations

0.9.7 • Public • Published

@polywrap/ethereum-plugin-js

The Ethereum plugin wrapper allows the Polywrap JS Client to interact with any EVM based blockchain.

Usage

import {
  ethereumPlugin,
  Connections,
  Connection
} from "@polywrap/ethereum-plugin-js";

export async function main() {

  const uri = "wrap://ens/ethereum.polywrap.eth"

  // initialize Ethereum Connections store
  const connections: Connections = new Connections({
    networks: {
      mainnet: new Connection({
        provider: "..."
      }),
      matic: new Connection({
        provider: window.ethereum
      })
    },
    defaultNetwork: "matic"
  });

  // initialize the client with the ethereum plugin
  client = new PolywrapClient({
    plugins: [
      {
        uri: uri,
        plugin: ethereumPlugin({ connections })
      }
    ]
  });

  // now you can invoke the ethereum plugin by its URI
  // NOTE: uses default network "matic"
  const getSignerAddress = await client.invoke<string>({
    uri,
    method: "getSignerAddress",
  });

  if (!getSignerAddress.ok) throw getSignerAddress.error;

  const address = getSignerAddress.value;

  // Get a balance from mainnet, by passing in the optional
  // "connection" argument.
  const getBalance = await client.invoke<string>({
    uri,
    method: "getBalance",
    args: {
      address: "0x...",
      connection: {
        networkNameOrChainId: "mainnet"
      }
    },
  });

  if (!getBalance.ok) throw getBalance.error;

  const balance = getBalance.value;

  console.log("Matic Signer: ", address);
  console.log("Mainnet Balance: ", balance);
}

For more usage examples see src/__tests__.

API

Full API in src/schema.graphql

Readme

Keywords

none

Package Sidebar

Install

npm i @polywrap/ethereum-plugin-js

Weekly Downloads

10

Version

0.9.7

License

MIT

Unpacked Size

256 kB

Total Files

34

Last publish

Collaborators

  • polywrap-build-bot
  • dorgjelli