npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

web3-plugin-eas

v0.0.4

Published

Web3.js plugin for Ethereum Attestation Service(EAS)

Downloads

9

Readme

Ethereum Attestation Service(EAS) Web3 Plugin

npm version

The Ethereum Attestation Service(EAS) Web3.js Plugin extends the capabilities of the Web3.js library to interact seamlessly with the Ethereum Attestation Service. This plugin provides convenient methods for interacting with the Ethereum Attestation Service(EAS) contracts.

Supported Features:

  • Get contract addresses of given network
  • Schema Registration
  • Attestations
  • Native Schema Encoder(WIP)

Installation

Note: Make sure you are using web3 version 4.0.3 or higher in your project.

npm install web3-plugin-eas web3@latest --save

Usage

Basic Usage

import { Web3 } from "web3";
import { EASPlugin } from "web3-plugin-eas";

const web3 = new Web3("https://rpc.ankr.com/eth"); // Any RPC node you wanted to connect with
web3.registerPlugin(new EASPlugin());

// Getting contract addresses of connected chain
const addresses = await web3.eas.getContractAddresses();

// or with given chain ID
// const addresses = await web3.eas.getContractAddresses(80001); // Chain ID of Polygon Mumbai

// Contract Instances
const schemaRegistry = web3.eas.schemaRegistry(addresses.schemaRegistry);
const easCore = web3.eas.easCore(addresses.eas);

// Getting schema record
const schemaUID =
  "0xd100943957d0f72cf5f93d55bea0dda8083817cd20af71863fe7efbb88eeb1ba"; // mainnet
const schemaRecord = await schemaRegistry.methods.getSchema(schemaUID).call();
console.log("Schema Record:", schemaRecord);

// Getting Attestation
const uid =
  "0xff08bbf3d3e6e0992fc70ab9b9370416be59e87897c3d42b20549901d2cccc3e";
const attestation = await easCore.methods.getAttestation(uid).call();
console.log("Attestation:", attestation);

Connecting Accounts to Web3

import { Web3 } from "web3";
import { EASPlugin } from "web3-plugin-eas";

// With any RPC node and private key
const web3 = new Web3("https://rpc.ankr.com/eth");
const wallet = web3.eth.accounts.wallet.add("0x..."); // Private Key
const { address: account } = wallet[0];

// or with browser wallets
const web3 = new Web3(window.ethereum);
const [account] = await window.ethereum.request({
  method: "eth_requestAccounts"
});

web3.registerPlugin(new EASPlugin());

// Getting contract addresses of connected chain
const addresses = await web3.eas.getContractAddresses();

// or with given chain ID
// const addresses = await web3.eas.getContractAddresses(80001); // Chain ID of Polygon Mumbai

// Contract Instances
const schemaRegistry = web3.eas.schemaRegistry(addresses.schemaRegistry);
const easCore = web3.eas.easCore(addresses.eas);

Schema Registry:

Registering Schema:

const schema = "uint256 eventId, uint8 voteIndex";
const resolver = "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0"; // Sepolia 0.26, or 0x00..
const revocable = false;

const registerSchemaTx = await schemaRegistry.methods
  .registerSchema(schema, resolver, revocable)
  .send({
    from: account,
    gas: 1000000
  });

console.log(registerSchemaTx);

Get Schema Info:

// Getting schema record
const schemaUID = "0xYourSchemaUID";
const schemaRecord = await schemaRegistry.methods.getSchema(schemaUID).call();
console.log("Record", schemaRecord);

Get Version:

const version = await schemaRegistry.methods.VERSION().call();
console.log(version); // 0.26

Refer EAS SchemaRegistry Docs for more information.

EAS Core:

Get Attestation:

const uid =
  "0xff08bbf3d3e6e0992fc70ab9b9370416be59e87897c3d42b20549901d2cccc3e";
const attestation = await easCore.methods.getAttestation(uid).call();
console.log(attestation);

Check if Attestation Valid:

const uid =
  "0xff08bbf3d3e6e0992fc70ab9b9370416be59e87897c3d42b20549901d2cccc3e";
const isValid = await easCore.methods.isAttestationValid(uid).call();
console.log(isValid);

Create Onchain Attestation:

import { SchemaEncoder } from "web3-plugin-eas";

// Initialize SchemaEncoder with the schema string
const schemaEncoder = new SchemaEncoder("uint256 eventId, uint8 voteIndex");
const encodedData = schemaEncoder.encodeData([
  { name: "eventId", value: 1, type: "uint256" },
  { name: "voteIndex", value: 1, type: "uint8" }
]);

const schemaUID =
  "0xb16fa048b0d597f5a821747eba64efa4762ee5143e9a80600d0005386edfc995";

// Create an instance of AttestationRequestData
const requestData = {
  recipient: "0xrecipientAddress", // Zero address if no recipient
  expirationTime: 0n, // expiration time in unix. 0 if no expiration
  revocable: true,
  refUID: "0x", // zero Bytes if none
  data: encodedData,
  value: 0 // Explicit ETH amount to send to the resolver
};

// Create an instance of AttestationRequest
const request = {
  schema: schemaUID,
  data: requestData
};

const tx = await easCore.methods.attest(request).send({
  from: account
});

console.log(tx);

Refer EAS Attestation Docs for more information

Publishing

To publish a new version of the package to npm, run the following command:

npm run build

npm publish

Change Log

0.0.4

  • Added example typescript project to demonstrate usage

0.0.3

  • Updated README.md examples

0.0.1

  • Initial Release
  • Get Contract Addresses
  • Schema Registration
  • Attestations

Resources

Safety

This is experimental software and subject to change over time.

This package is not audited and has not been tested for security. Use at your own risk. I do not give any warranties and will not be liable for any loss incurred through any use of this codebase.

License

This project is licensed under the MIT License - see the LICENSE file for details