Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use eas dao & event registry #29

Open
codingshot opened this issue Oct 2, 2024 · 1 comment
Open

use eas dao & event registry #29

codingshot opened this issue Oct 2, 2024 · 1 comment

Comments

@codingshot
Copy link
Member

how would you replace this database with attest.org ethereum attestation service.

To replace the current JSON-based database with Ethereum attestations using attest.org (Ethereum Attestation Service), we'll need to make several changes to the application. Here's a high-level overview of the steps and changes required:

  1. Set up EAS (Ethereum Attestation Service):
    Create an EAS schema for DAO data
    Deploy the schema to the desired network (e.g., mainnet, testnet)
    Update the data storage:
    Instead of using a local JSON file, we'll store DAO data as attestations on-chain
    Modify the data fetching logic:
    Replace the import of the JSON file with a function to fetch attestations from EAS
    Update the filtering and search functionality:
    Implement filtering and searching on the client-side or use EAS's GraphQL API for more efficient querying
    Modify the DAO submission process:
    Instead of opening a GitHub link, create a form to submit new DAO attestations
    Here's a more detailed breakdown of the changes:
    Set up EAS schema:
    struct DAOData {
    string name;
    string icon;
    string url;
    string description;
    string[] maturity;
    string[] tags;
    string twitter;
    string github;
    string emoji;
    string banner;
    bool featured;
    uint256 order;
    }
  2. Update data fetching:
    d-a-os-description.tsx
    import { EAS, SchemaEncoder } from "@ethereum-attestation-service/eas-sdk";

const EAS_CONTRACT_ADDRESS = "0x..."; // EAS contract address
const EAS_SCHEMA_UID = "0x..."; // Your schema UID

const eas = new EAS(EAS_CONTRACT_ADDRESS);

// ... existing imports and component code ...

const DAOsDescription: NextPage = ({ className = "" , mode = "explore" }) => {
// ... existing state variables ...

const [daoData, setDaoData] = useState<DAO[]>([]);

useEffect(() => {
const fetchDAOs = async () => {
setIsLoading(true);
try {
const attestations = await eas.getAttestationsBySchema(EAS_SCHEMA_UID);
const decodedDAOs = attestations.map(attestation => {
const decodedData = eas.decodeAttestationData(attestation);
return {
name: decodedData.name,
icon: decodedData.icon,
url: decodedData.url,
description: decodedData.description,
maturity: decodedData.maturity,
tags: decodedData.tags,
twitter: decodedData.twitter,
github: decodedData.github,
// ... other fields ...
};
});
setDaoData(decodedDAOs);
} catch (error) {
console.error("Error fetching DAOs:", error);
}
setIsLoading(false);
};

fetchDAOs();

}, []);

// ... rest of the component code ...
};
Update filtering and search:
d-a-os-description.tsx
useEffect(() => {
const filtered = daoData.filter(dao => {
const matchesSearch =
dao.name.toLowerCase().includes(searchTerm.toLowerCase()) ||
dao.description.toLowerCase().includes(searchTerm.toLowerCase());

const matchesMaturity = selectedMaturity.length === 0 || 
  selectedMaturity.every(tag => dao.maturity.includes(tag));

const matchesTags = selectedTags.length === 0 || 
  selectedTags.every(tag => dao.tags.includes(tag));

return matchesSearch && matchesMaturity && matchesTags;

});
setFilteredDAOs(filtered);
}, [searchTerm, selectedMaturity, selectedTags, daoData]);
Modify DAO submission:
d-a-os-description.tsx
import { ethers } from 'ethers';

// ... existing component code ...

const handleSubmitDAO = async (daoData: DAO) => {
if (typeof window.ethereum !== 'undefined') {
try {
await window.ethereum.request({ method: 'eth_requestAccounts' });
const provider = new ethers.providers.Web3Provider(window.ethereum);
const signer = provider.getSigner();

  const schemaEncoder = new SchemaEncoder("string name,string icon,string url,string description,string[] maturity,string[] tags,string twitter,string github,string emoji,string banner,bool featured,uint256 order");
  const encodedData = schemaEncoder.encodeData([
    { name: "name", value: daoData.name, type: "string" },
    { name: "icon", value: daoData.icon, type: "string" },
    // ... encode other fields ...
  ]);

  const tx = await eas.connect(signer).attest({
    schema: EAS_SCHEMA_UID,
    data: {
      recipient: "0x0000000000000000000000000000000000000000",
      expirationTime: 0,
      revocable: true,
      data: encodedData,
    },
  });

  await tx.wait();
  console.log("DAO submitted successfully!");
} catch (error) {
  console.error("Error submitting DAO:", error);
}

} else {
console.log("Please install MetaMask!");
}
};

// Replace the existing Submit DAO button with a form or modal to collect DAO data
These changes will replace the JSON-based database with on-chain attestations using EAS. Note that this is a significant architectural change and will require additional considerations:

  1. Gas costs for creating attestations
    User experience for submitting DAOs (requiring MetaMask or another web3 wallet)
    Potential delays in data updates due to blockchain confirmation times
    Handling of schema updates and data migrations
    You'll also need to create a more comprehensive form for DAO submission and handle the connection to the user's Ethereum wallet. Additionally, you may want to implement a caching layer to improve performance and reduce the number of blockchain queries.
@codingshot
Copy link
Member Author

attest.org

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant