schema/
schema.rs

1use eas_sdk_rs::eas::AttestationDataBuilder;
2use eas_sdk_rs::{client, schema};
3use ethers::abi::Token;
4use ethers::core::k256::ecdsa::SigningKey;
5use ethers::prelude::*;
6use ethers::utils::hex;
7use std::error::Error;
8use std::str::FromStr;
9
10const SEPOLIA_CONTRACT_ADDRESS: &str = "0xC2679fBD37d54388Ce493F1DB75320D236e1815e";
11const SEPOLIA_ENDPOINT: &str = "https://ethereum-sepolia-rpc.publicnode.com/";
12const SEPOLIA_PRIVATE_KEY_HEX: &str = "enter your private key here";
13
14#[tokio::main]
15async fn main() -> Result<(), Box<dyn Error>> {
16    let singing_key = &hex::decode(SEPOLIA_PRIVATE_KEY_HEX)?;
17    let signing_key = SigningKey::from_slice(singing_key)?;
18    let contract_address = H160::from_str(SEPOLIA_CONTRACT_ADDRESS)?;
19    let client = client::Client::new(SEPOLIA_ENDPOINT, contract_address, None, signing_key).await?;
20
21    let schema = schema::SchemaBuilder::new()
22        .add("id", schema::Type::Address)
23        .add("voter_id", schema::Type::Address)
24        .add("vote_option", schema::Type::Int(32))
25        .build();
26
27    let tx = client.schema_registry.register(schema, None, true).await?;
28    let registered_schema = tx.await?;
29
30    println!("Schema ID: {:?}", registered_schema.schema_uid);
31
32    let naming_schema =
33        H256::from_str("0x44d562ac1d7cd77e232978687fea027ace48f719cf1d58c7888e509663bb87fc")?;
34
35    let data = &[
36        Token::FixedBytes(registered_schema.schema_uid.as_bytes().into()),
37        Token::String("enter schema name here".to_string()),
38    ];
39
40    let attestation_data = AttestationDataBuilder::new()
41        .revocable(true)
42        .data(data)
43        .build();
44
45    let attested = client.eas.attest(&naming_schema, attestation_data).await?;
46    let attested = attested.await?;
47
48    println!("Attestation ID: {:?}", attested);
49
50    Ok(())
51}