Skip to content

Instantly share code, notes, and snippets.

@sarvagnakadiya
Last active September 19, 2024 07:41
Show Gist options
  • Save sarvagnakadiya/a4203e44a609c46b6fa630e5b7a77126 to your computer and use it in GitHub Desktop.
Save sarvagnakadiya/a4203e44a609c46b6fa630e5b7a77126 to your computer and use it in GitHub Desktop.
"use client";
import React from "react";
import {
SignProtocolClient,
SpMode,
OffChainSignType,
OffChainRpc,
DataLocationOffChain,
IndexService,
} from "@ethsign/sp-sdk";
import { useWalletClient } from "wagmi";
// import { createWalletClient, custom, http } from "viem";
// import { arbitrumSepolia } from "viem/chains";
function page() {
const { data: walletClient, isError, isLoading } = useWalletClient();
console.log(walletClient);
// const wclient = createWalletClient({
// chain: arbitrumSepolia,
// transport: http(
// "https://arb-sepolia.g.alchemy.com/v2/VTw-hkd9ryjCAozXE_MLJNRWvr_FM4Ma"
// ),
// });
const client = new SignProtocolClient(SpMode.OffChain, {
signType: OffChainSignType.EvmEip712,
rpcUrl: OffChainRpc.testnet,
walletClient: walletClient,
});
console.log(client);
const handleCreateSchema = async () => {
const schemaInfo = await client.createSchema({
name: "from sdk",
data: [
{ name: "receiver", type: "address" },
{ name: "token", type: "address" },
{ name: "amount", type: "uint256" },
{ name: "chainId", type: "uint256" },
{ name: "sign", type: "bytes" },
],
dataLocation: DataLocationOffChain.IPFS,
});
console.log(schemaInfo);
};
const handleAttest = async () => {
// Create attestation
const schemahex = await client.getSchema("SPS_Y8tHQJa7DiEnQTU_qyIQW");
console.log(schemahex);
const attestationInfo = await client.createAttestation({
schemaId: "SPS_Y8tHQJa7DiEnQTU_qyIQW",
data: {
receiver: "0xE42c136730A9CfeFb5514D4d3D06EB27BAAf3f08",
token: "0x14D525378D1Df14e5a39d10a97E07B5F96373f5A",
amount: "1000000",
chainId: "421614",
sign: "0x6bdb85deb35df0a61020af5adaab61807c11d68843262efde90095e0e32704c44e28aea2a3ee30a94f8d2a491148d9ad21b4d60bd3998abad984796930e836c81b",
// age: 24,
},
recipients: ["0xE42c136730A9CfeFb5514D4d3D06EB27BAAf3f08"],
indexingValue: "0",
});
console.log(attestationInfo);
};
const getData = async () => {
const indexService = new IndexService("testnet");
const res = await indexService.querySchema("SPS_To8Y1mi_3gfAIMFy1An-z");
const list = await indexService.queryAttestationList({
schemaId: "SPS_To8Y1mi_3gfAIMFy1An-z",
page: 1,
});
console.log(res);
console.log(list);
};
return (
<div>
<button onClick={handleAttest}>attest</button>
<br></br>
<button onClick={handleCreateSchema}>create</button>
<br></br>
<button onClick={getData}>getData</button>
<br></br>
</div>
);
}
export default page;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment