ethereum-attestation-service / eas-sdk

Ethereum Attestation Service - TypeScript/JavaScript SDK
MIT License
83 stars 38 forks source link

TypeError: (0 , ethers_1.toUtf8Bytes) is not a function #90

Closed Seroxdesign closed 3 months ago

Seroxdesign commented 3 months ago

I am trying to integrate eas-sdk into a Next13 repo:

I have tried both version 1.5.0, and the beta 2.0.0v yet I can't get this working.

I am using Wagmi/Viem V2s EthersSigner adapter

My hook

import  { EAS, SchemaEncoder }  from "@ethereum-attestation-service/eas-sdk";
import { TransactionSigner } from "@ethereum-attestation-service/eas-sdk";
import { useEthersSigner } from "./userEthersSigner";
import { useEffect, useState } from "react";

// EAS Schema https://optimism.easscan.org/schema/view/0x081fc803f607b291b727b885a203d53b8cbb1488f6db1242327cca81db5f17ed

const easContractAddress = "0x4200000000000000000000000000000000000021";
const schemaUID = "0x081fc803f607b291b727b885a203d53b8cbb1488f6db1242327cca81db5f17ed";
const eas = new EAS(easContractAddress); // ERROR HERE: TypeError: (0 , ethers_1.toUtf8Bytes) is not a function

export const useEAS = () => {
  const [connectedEAS, setConnectedEAS] = useState<EAS | null>(null);
  const provider = useEthersSigner({ chainId: 10 });

  useEffect(() => {
    const connectEAS = async () => {
      if (provider) {
        eas.connect(provider); // TYPE ERROR HERE Argument of type  is not assignable to parameter of type Transaction Signer

      }
      setConnectedEAS(eas);
    }
    connectEAS();
  }, [provider])

  const attest = async (message: string, context: string) => {
     // Initialize SchemaEncoder with the schema string
  const schemaEncoder = new SchemaEncoder("string message,string context");
    const encodedData = schemaEncoder.encodeData([
      { name: "message", value: message, type: "string" },
      { name: "context", value: context, type: "string" }
    ]);
    const tx = await eas.attest({
      schema: schemaUID,
      data: {
        recipient: "0x0000000000000000000000000000000000000000",
        expirationTime: 0 as unknown as bigint,
        revocable: true, // Be aware that if your schema is not revocable, this MUST be false
        data: encodedData,
      },
    });
    const newAttestationUID = await tx.wait();
    console.log("New attestation UID:", newAttestationUID);
  }

  return { connectedEAS, attest };
}

I haven't been able to move this forward, looked into the open/closed issues on Github.

Seroxdesign commented 3 months ago

Well, I figured it out. We were hoisting the ethers version to 5 which was causing a conflict with the SDK given it uses ethers v6 methods. I'm going to close this.

lbeder commented 2 months ago

I was just about to write that myself. Happy to hear that you were able to sort it out!