Skip to content

Commit

Permalink
added attestation
Browse files Browse the repository at this point in the history
  • Loading branch information
KENILSHAHH committed Jun 30, 2024
1 parent 8f8fe23 commit b811d51
Show file tree
Hide file tree
Showing 7 changed files with 1,798 additions and 52 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"node": ">=18.17.0"
},
"dependencies": {
"@coinbase/onchainkit": "^0.23.4",
"@emotion/react": "^11.11.4",
"@emotion/styled": "^11.11.5",
"@ethereum-attestation-service/eas-sdk": "^2.3.0",
Expand Down
34 changes: 34 additions & 0 deletions packages/nextjs/app/api/orchestrator/[frameId]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import { FrameRequest, getFrameHtmlResponse } from "@coinbase/onchainkit";
import Analytics from "~~/model/analytics";
import connectDB from "~~/services/connectDB";
import { getFrameAtServer } from "~~/services/frames";
import { EAS, SchemaEncoder, SchemaRegistry } from "@ethereum-attestation-service/eas-sdk";
import { ethers } from "ethers";


const storeAnalytics = async (body: FrameRequest, state: any) => {
const analyticsEntry = new Analytics({
Expand All @@ -16,7 +19,38 @@ const storeAnalytics = async (body: FrameRequest, state: any) => {
await analyticsEntry.save();
console.log(analyticsEntry);
};
async function createAttestation(txnId : string){
const eas = new EAS("0x4200000000000000000000000000000000000021");
const offchain = await eas.getOffchain();
const provider = new ethers.JsonRpcProvider("https://base-sepolia.infura.io/v3/847856edbfc14f50a4782dce0fa77ce5")
// Signer must be an ethers-like signer.
const schemaUID = "0x3ca31d9c24a48e437eba25cb423d9a873a751511c70dc0b2a8fb4c9a8d45b506"
const signer = new ethers.Wallet("c04f2876f3691d44fdba3592bf800c05516d419f10ac269a7a565c21dfda57fa", provider);
const schemaEncoder = new SchemaEncoder("address seller,address buyer,uint256 amount,uint256 quantity,bytes32 txHash,string productId");
const encodedData = schemaEncoder.encodeData([
{ name: "seller", value: "0x0000000000000000000000000000000000000000", type: "address" },
{ name: "buyer", value: "0x0000000000000000000000000000000000000000", type: "address" },
{ name: "amount", value: "0", type: "uint256" },
{ name: "quantity", value: "0", type: "uint256" },
{ name: "txHash", value: {txnId}, type: "bytes32" },
{ name: "productId", value: "", type: "string" },
]);

const tx = await eas.attest({
schema: schemaUID,
data: {
recipient: "0x0000000000000000000000000000000000000000",
expirationTime: BigInt(0),
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 newAttestationUID;
}
async function getResponse(req: NextRequest): Promise<NextResponse> {
await connectDB();
const url = req.nextUrl.pathname;
Expand Down
Loading

0 comments on commit b811d51

Please sign in to comment.