Skip to content

Commit

Permalink
Merge pull request #5 from NikosFotiadis/feat/switch-network
Browse files Browse the repository at this point in the history
Feat/switch network
  • Loading branch information
NikosFotiadis authored Nov 18, 2023
2 parents d64c846 + 5189757 commit 5debec4
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 18 deletions.
6 changes: 2 additions & 4 deletions packages/nextjs/components/AccountAbstractionAttestations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ const AccountAbstractionAttestations: React.FC<ScanComponentProps> = props => {

return (
<div>
{/* {data.map(attestation => (
{data.map(attestation => (
<div key={attestation.args!.uid}>{attestation.args!.uid ? attestation.args!.uid.slice(0, 10) : ""}</div>
))} */}

Att here
))}
</div>
);
};
Expand Down
6 changes: 3 additions & 3 deletions packages/nextjs/contracts/externalContracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import { GenericContractsDeclaration } from "~~/utils/scaffold-eth/contract";
const externalContracts = {
1: {
EAS: {
address: "0xC2679fBD37d54388Ce493F1DB75320D236e1815e",
deployedAt: 4717894,
address: "0x4200000000000000000000000000000000000021",
deployedAt: 12565960,
abi: [
{
inputs: [{ internalType: "contract ISchemaRegistry", name: "registry", type: "address" }],
Expand Down Expand Up @@ -464,7 +464,7 @@ const externalContracts = {
],
},
SchemaRegistry: {
address: "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0",
address: "0x4200000000000000000000000000000000000020",
abi: [
{ inputs: [], name: "AlreadyExists", type: "error" },
{
Expand Down
2 changes: 1 addition & 1 deletion packages/nextjs/scaffold.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type ScaffoldConfig = {

const scaffoldConfig = {
// The network where your DApp lives in
targetNetwork: chains.sepolia,
targetNetwork: chains.baseGoerli,

// The interval at which your front-end polls the RPC servers for new data
// it has no effect on the local network
Expand Down
33 changes: 27 additions & 6 deletions packages/nextjs/services/web3/attestationService.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable @typescript-eslint/no-non-null-assertion */
import { getSigner } from "./ethersSigner";
import { getProvider, getSigner } from "./ethersSigner";
import { Attestation, EAS, SchemaEncoder, SchemaRecord, SchemaRegistry } from "@ethereum-attestation-service/eas-sdk";
import { Contract } from "ethers";
import externalContracts from "~~/contracts/externalContracts";

const EASContractAddress = "0xC2679fBD37d54388Ce493F1DB75320D236e1815e"; // Sepolia v0.26
const schemaRegistryContractAddress = "0x0a7E2Ff54e76B8E6659aedc9103FB21c038050D0";
const resolverAddress = "0x0000000000000000000000000000000000000000"; // Sepolia 0.26
const EASContractAddress = "0x4200000000000000000000000000000000000021";
const schemaRegistryContractAddress = "0x4200000000000000000000000000000000000020";
const resolverAddress = "0x0000000000000000000000000000000000000000";
const schemaUID = "0x95e10aa7a515d68dafbfd739b4c9ed7afb40e1fbe8f7a1468501de02fc334c28";

const createAttendeeSchemaData = ({ eventId, eventName }: { eventId: string; eventName: string }): any => {
Expand Down Expand Up @@ -91,12 +91,12 @@ export const createMultiAttestation = async (addresses: string[], attestation: s
};

export const getAttestationsForAddress = async (userAddress: string) => {
const signer = await getSigner();
const provider = await getProvider();

const address = externalContracts[1].EAS.address;
const abi = externalContracts[1].EAS.abi;
const fromBlock = externalContracts[1].EAS.deployedAt;
const EASInstance = new Contract(address, abi, signer);
const EASInstance = new Contract(address, abi, provider);

const attested = await EASInstance.queryFilter("Attested", fromBlock);

Expand All @@ -105,6 +105,27 @@ export const getAttestationsForAddress = async (userAddress: string) => {
});
};

// Return all the attestations where you are the organizer
export const getOrganizerAttestationsForAddress = async (userAddress: string) => {
const provider = await getProvider();

const address = externalContracts[1].EAS.address;
const abi = externalContracts[1].EAS.abi;
const fromBlock = externalContracts[1].EAS.deployedAt;
const EASInstance = new Contract(address, abi, provider);

const attested = await EASInstance.queryFilter("Attested", fromBlock);

// Events for which you self attested are the ones where you are the organizer
const res = attested.filter(event => {
return (
event.args!.recipient === userAddress && event.args!.schema === schemaUID && event.args!.attester === userAddress
);
});

return res;
};

const createAttestationSchema = async () => {
const signer = await getSigner();
const schemaRegistry = new SchemaRegistry(schemaRegistryContractAddress);
Expand Down
31 changes: 27 additions & 4 deletions packages/nextjs/services/web3/ethersSigner.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,36 @@
import { type WalletClient, getWalletClient } from "@wagmi/core";
import { type PublicClient, type WalletClient, getPublicClient, getWalletClient } from "@wagmi/core";
import { providers } from "ethers";
import { sepolia } from "wagmi/chains";
import { type HttpTransport } from "viem";
import { baseGoerli } from "wagmi/chains";

export function walletClientToSigner(walletClient: WalletClient) {
const { account, chain = sepolia, transport } = walletClient;
const { account, chain = baseGoerli, transport } = walletClient;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
const provider = new providers.Web3Provider(transport, network);
const signer = provider.getSigner(account.address);

return signer;
}

export function publicClientToProvider(publicClient: PublicClient) {
const { chain, transport } = publicClient;
const network = {
chainId: chain.id,
name: chain.name,
ensAddress: chain.contracts?.ensRegistry?.address,
};
if (transport.type === "fallback")
return new providers.FallbackProvider(
(transport.transports as ReturnType<HttpTransport>[]).map(
({ value }) => new providers.JsonRpcProvider(value?.url, network),
),
);
return new providers.JsonRpcProvider(transport.url, network);
}

export const getSigner = async () => {
const walletClient = await getWalletClient();

Expand All @@ -23,3 +39,10 @@ export const getSigner = async () => {

return signer;
};

export const getProvider = async () => {
const publicClient = await getPublicClient();
const provider = publicClientToProvider(publicClient);

return provider;
};

0 comments on commit 5debec4

Please sign in to comment.