0.9.7 • Published 1 year ago

@polywrap/ethereum-plugin-js v0.9.7

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

@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

0.9.7

1 year ago

0.9.6

1 year ago

0.9.5

1 year ago

0.10.0-pre.8

1 year ago

0.10.0-pre.7

1 year ago

0.10.0-pre.6

1 year ago

0.10.0-pre.3

1 year ago

0.10.0-pre.4

1 year ago

0.10.0-pre.1

1 year ago

0.10.0-pre.5

1 year ago

0.9.4

2 years ago

0.9.3

2 years ago

0.10.0-pre.0

2 years ago

0.9.0

2 years ago

0.9.2

2 years ago

0.9.1

2 years ago

0.8.0

2 years ago

0.5.0

2 years ago

0.4.1

2 years ago

0.7.0

2 years ago

0.6.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago