Documentation ¶
Overview ¶
Example (StructuredAttestation) ¶
Attest a road trip with a structured schema.
package main import ( "context" "log" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "resenje.org/eas" ) var ( endpointSepolia = "https://ethereum-sepolia-rpc.publicnode.com/" contractAddressSepolia = common.HexToAddress("0xC2679fBD37d54388Ce493F1DB75320D236e1815e") ) type RoadTrip struct { ID uint64 `abi:"id"` VIN string `abi:"vin"` VehicleOwner string `abi:"vehicleOwner"` Passengers []Passenger `abi:"passengers"` } type Passenger struct { Name string `abi:"name"` CanDrive bool `abi:"canDrive"` } func (p Passenger) CanDriveString() string { if p.CanDrive { return "can drive" } return "cannot drive" } func main() { ctx := context.Background() // Use a fake key here. Use your own funded key to be able to send transactions. privateKey, err := eas.HexParsePrivateKey("a896e1f28a6453e8db4794f11ea185befd04c4e4f06790e37e8d1cc90a611948") if err != nil { log.Fatal(err) } log.Println("Wallet address:", crypto.PubkeyToAddress(privateKey.PublicKey)) // Construct a client that will interact with EAS contracts. c, err := eas.NewClient(ctx, endpointSepolia, privateKey, contractAddressSepolia, nil) if err != nil { log.Fatal(err) } // Create the Schema on chain. tx, waitRegistration, err := c.SchemaRegistry.Register(ctx, eas.MustNewSchema(RoadTrip{}), common.Address{}, true) if err != nil { log.Fatal(err) } log.Println("Waiting schema registration transaction:", tx.Hash()) schemaRegistration, err := waitRegistration(ctx) if err != nil { log.Fatal(err) } // Just check the schema definition. schema, err := c.SchemaRegistry.GetSchema(ctx, schemaRegistration.UID) if err != nil { log.Fatal(err) } log.Println("Schema UID:", schema.UID) log.Println("Schema:", schema.Schema) // Attest a road trip on chain. tx, waitAttestation, err := c.EAS.Attest(ctx, schema.UID, &eas.AttestOptions{Revocable: true}, RoadTrip{ ID: 4242, VIN: "1FA6P8CF5L5100421", VehicleOwner: "Richard Hammond", Passengers: []Passenger{ { Name: "James May", CanDrive: true, }, { Name: "Jeremy Clarkson", CanDrive: true, }, { Name: "The Stig", CanDrive: false, }, }, }, ) if err != nil { log.Fatal(err) } log.Println("Waiting attest transaction:", tx.Hash()) attestConfirmation, err := waitAttestation(ctx) if err != nil { log.Fatal(err) } // Get the attestation to verify it. a, err := c.EAS.GetAttestation(ctx, attestConfirmation.UID) if err != nil { log.Fatal(err) } log.Println("Attestation UID", a.UID) log.Println("Attestation Time", a.Time) var roadTrip RoadTrip if err := a.ScanValues(&roadTrip); err != nil { log.Fatal(err) } log.Println("Road trip:", roadTrip.ID) log.Println("Vehicle Identification Number:", roadTrip.VIN) log.Println("Vehicle owner:", roadTrip.VehicleOwner) for i, p := range roadTrip.Passengers { log.Printf("Passenger %v: %s (%s)", i, p.Name, p.CanDriveString()) } }
Output:
Index ¶
- func HexParsePrivateKey(h string) (*ecdsa.PrivateKey, error)
- func LoadEthereumKeyFile(fs fs.FS, filename, auth string) (*ecdsa.PrivateKey, error)
- func MustNewSchema(args ...any) string
- func NewSchema(args ...any) (string, error)
- func Ptr[T any](v T) *T
- type AttestOptions
- type Attestation
- type Backend
- type Client
- type ContractError
- type ContractErrorArgument
- type EASAttested
- type EASContract
- func (c *EASContract) Attest(ctx context.Context, schemaUID UID, o *AttestOptions, values ...any) (*types.Transaction, WaitTx[EASAttested], error)
- func (c *EASContract) FilterAttested(ctx context.Context, start uint64, end *uint64, recipient []common.Address, ...) (Iterator[EASAttested], error)
- func (c *EASContract) FilterRevoked(ctx context.Context, start uint64, end *uint64, recipient []common.Address, ...) (Iterator[EASRevoked], error)
- func (c *EASContract) FilterRevokedOffchain(ctx context.Context, start uint64, end *uint64, revoker []common.Address, ...) (Iterator[EASRevokedOffchain], error)
- func (c *EASContract) FilterTimestamped(ctx context.Context, start uint64, end *uint64, data []UID, ...) (Iterator[EASTimestamped], error)
- func (c *EASContract) GetAttestation(ctx context.Context, uid UID) (*Attestation, error)
- func (c *EASContract) GetRevokeOffchain(ctx context.Context, revoker common.Address, uid UID) (uint64, error)
- func (c *EASContract) GetTimestamp(ctx context.Context, data UID) (Timestamp, error)
- func (c *EASContract) IsAttestationValid(ctx context.Context, uid UID) (bool, error)
- func (c *EASContract) MultiAttest(ctx context.Context, schemaUID UID, o *AttestOptions, attestations ...[]any) (*types.Transaction, WaitTxMulti[EASAttested], error)
- func (c *EASContract) MultiRevoke(ctx context.Context, schemaUID UID, attestationUIDs []UID) (*types.Transaction, WaitTxMulti[EASRevoked], error)
- func (c *EASContract) MultiRevokeOffchain(ctx context.Context, schemaUID UID, uids []UID) (*types.Transaction, WaitTxMulti[EASRevokedOffchain], error)
- func (c *EASContract) MultiTimestamp(ctx context.Context, data []UID) (*types.Transaction, WaitTxMulti[EASTimestamped], error)
- func (c *EASContract) Revoke(ctx context.Context, schemaUID, attestationUID UID, o *RevokeOptions) (*types.Transaction, WaitTx[EASRevoked], error)
- func (c *EASContract) RevokeOffchain(ctx context.Context, uid UID) (*types.Transaction, WaitTx[EASRevokedOffchain], error)
- func (c *EASContract) Timestamp(ctx context.Context, data UID) (*types.Transaction, WaitTx[EASTimestamped], error)
- func (c *EASContract) Version(ctx context.Context) (string, error)
- func (c *EASContract) WatchAttested(ctx context.Context, start *uint64, sink chan<- *EASAttested, ...) (event.Subscription, error)
- func (c *EASContract) WatchRevoked(ctx context.Context, start *uint64, sink chan<- *EASRevoked, ...) (event.Subscription, error)
- func (c *EASContract) WatchRevokedOffchain(ctx context.Context, start *uint64, sink chan<- *EASRevokedOffchain, ...) (event.Subscription, error)
- func (c *EASContract) WatchTimestamped(ctx context.Context, start *uint64, sink chan<- *EASTimestamped, data []UID, ...) (event.Subscription, error)
- type EASRevoked
- type EASRevokedOffchain
- type EASTimestamped
- type Error
- type Iterator
- type Options
- type RevokeOptions
- type SchemaRecord
- type SchemaRegistryContract
- func (c *SchemaRegistryContract) FilterRegistered(ctx context.Context, start uint64, end *uint64, uids []UID) (Iterator[*SchemaRegistryRegistered], error)
- func (c *SchemaRegistryContract) GetSchema(ctx context.Context, uid UID) (*SchemaRecord, error)
- func (c *SchemaRegistryContract) Register(ctx context.Context, schema string, resolver common.Address, revocable bool) (*types.Transaction, WaitTx[SchemaRegistryRegistered], error)
- func (c *SchemaRegistryContract) Version(ctx context.Context) (string, error)
- func (c *SchemaRegistryContract) WatchRegistered(ctx context.Context, start *uint64, sink chan<- *SchemaRegistryRegistered, ...) (event.Subscription, error)
- type SchemaRegistryRegistered
- type Timestamp
- type UID
- type WaitTx
- type WaitTxMulti
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HexParsePrivateKey ¶
func HexParsePrivateKey(h string) (*ecdsa.PrivateKey, error)
func LoadEthereumKeyFile ¶
func MustNewSchema ¶
Types ¶
type AttestOptions ¶
type Attestation ¶
type Attestation struct { UID UID Schema UID Time time.Time ExpirationTime time.Time RevocationTime time.Time RefUID UID Recipient common.Address Attester common.Address Revocable bool Data []byte }
func (Attestation) IsRevoked ¶
func (a Attestation) IsRevoked() bool
func (Attestation) ScanValues ¶
func (a Attestation) ScanValues(fields ...any) error
type Backend ¶
type Backend interface { bind.ContractBackend bind.DeployBackend ethereum.ChainIDReader }
type Client ¶
type Client struct { // Contracts SchemaRegistry *SchemaRegistryContract EAS *EASContract // contains filtered or unexported fields }
type ContractError ¶
type ContractError struct { Name string Arguments []ContractErrorArgument }
func (*ContractError) Error ¶
func (e *ContractError) Error() string
type ContractErrorArgument ¶
type EASAttested ¶
type EASContract ¶
type EASContract struct {
// contains filtered or unexported fields
}
func (*EASContract) Attest ¶
func (c *EASContract) Attest(ctx context.Context, schemaUID UID, o *AttestOptions, values ...any) (*types.Transaction, WaitTx[EASAttested], error)
func (*EASContract) FilterAttested ¶
func (*EASContract) FilterRevoked ¶
func (*EASContract) FilterRevokedOffchain ¶
func (*EASContract) FilterTimestamped ¶
func (c *EASContract) FilterTimestamped(ctx context.Context, start uint64, end *uint64, data []UID, timestamps []Timestamp) (Iterator[EASTimestamped], error)
func (*EASContract) GetAttestation ¶
func (c *EASContract) GetAttestation(ctx context.Context, uid UID) (*Attestation, error)
Example ¶
package main import ( "context" "log" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/crypto" "resenje.org/eas" ) var ( endpointSepolia = "https://ethereum-sepolia-rpc.publicnode.com/" contractAddressSepolia = common.HexToAddress("0xC2679fBD37d54388Ce493F1DB75320D236e1815e") ) func main() { ctx := context.Background() privateKey, err := crypto.GenerateKey() if err != nil { log.Fatal(err) } c, err := eas.NewClient(ctx, endpointSepolia, privateKey, contractAddressSepolia, nil) if err != nil { log.Fatal(err) } attestationUID := eas.HexDecodeUID("0xac812932f5cee90a457d57a9fbd7b142b21ba99b809f982bbf86947f295281ff") a, err := c.EAS.GetAttestation(ctx, attestationUID) if err != nil { log.Fatal(err) } log.Println("Attestation UID", a.UID) log.Println("Attestation Time", a.Time) var schemaUID eas.UID var name string if err := a.ScanValues(&schemaUID, &name); err != nil { log.Fatal(err) } log.Println("Attestation") log.Println("Schema UID:", schemaUID) log.Println("Name:", name) }
Output:
func (*EASContract) GetRevokeOffchain ¶
func (*EASContract) GetTimestamp ¶
func (*EASContract) IsAttestationValid ¶
func (*EASContract) MultiAttest ¶
func (c *EASContract) MultiAttest(ctx context.Context, schemaUID UID, o *AttestOptions, attestations ...[]any) (*types.Transaction, WaitTxMulti[EASAttested], error)
func (*EASContract) MultiRevoke ¶
func (c *EASContract) MultiRevoke(ctx context.Context, schemaUID UID, attestationUIDs []UID) (*types.Transaction, WaitTxMulti[EASRevoked], error)
func (*EASContract) MultiRevokeOffchain ¶
func (c *EASContract) MultiRevokeOffchain(ctx context.Context, schemaUID UID, uids []UID) (*types.Transaction, WaitTxMulti[EASRevokedOffchain], error)
func (*EASContract) MultiTimestamp ¶
func (c *EASContract) MultiTimestamp(ctx context.Context, data []UID) (*types.Transaction, WaitTxMulti[EASTimestamped], error)
func (*EASContract) Revoke ¶
func (c *EASContract) Revoke(ctx context.Context, schemaUID, attestationUID UID, o *RevokeOptions) (*types.Transaction, WaitTx[EASRevoked], error)
func (*EASContract) RevokeOffchain ¶
func (c *EASContract) RevokeOffchain(ctx context.Context, uid UID) (*types.Transaction, WaitTx[EASRevokedOffchain], error)
func (*EASContract) Timestamp ¶
func (c *EASContract) Timestamp(ctx context.Context, data UID) (*types.Transaction, WaitTx[EASTimestamped], error)
func (*EASContract) WatchAttested ¶
func (c *EASContract) WatchAttested(ctx context.Context, start *uint64, sink chan<- *EASAttested, recipient []common.Address, attester []common.Address, schema []UID) (event.Subscription, error)
func (*EASContract) WatchRevoked ¶
func (c *EASContract) WatchRevoked(ctx context.Context, start *uint64, sink chan<- *EASRevoked, recipient []common.Address, attester []common.Address, schema []UID) (event.Subscription, error)
func (*EASContract) WatchRevokedOffchain ¶
func (c *EASContract) WatchRevokedOffchain(ctx context.Context, start *uint64, sink chan<- *EASRevokedOffchain, revoker []common.Address, data []UID, timestamp []uint64) (event.Subscription, error)
func (*EASContract) WatchTimestamped ¶
func (c *EASContract) WatchTimestamped(ctx context.Context, start *uint64, sink chan<- *EASTimestamped, data []UID, timestamps []Timestamp) (event.Subscription, error)
type EASRevoked ¶
type EASRevokedOffchain ¶
type RevokeOptions ¶
type SchemaRecord ¶
type SchemaRegistryContract ¶
type SchemaRegistryContract struct {
// contains filtered or unexported fields
}
func (*SchemaRegistryContract) FilterRegistered ¶
func (c *SchemaRegistryContract) FilterRegistered(ctx context.Context, start uint64, end *uint64, uids []UID) (Iterator[*SchemaRegistryRegistered], error)
func (*SchemaRegistryContract) GetSchema ¶
func (c *SchemaRegistryContract) GetSchema(ctx context.Context, uid UID) (*SchemaRecord, error)
func (*SchemaRegistryContract) Register ¶
func (c *SchemaRegistryContract) Register(ctx context.Context, schema string, resolver common.Address, revocable bool) (*types.Transaction, WaitTx[SchemaRegistryRegistered], error)
func (*SchemaRegistryContract) Version ¶
func (c *SchemaRegistryContract) Version(ctx context.Context) (string, error)
func (*SchemaRegistryContract) WatchRegistered ¶
func (c *SchemaRegistryContract) WatchRegistered(ctx context.Context, start *uint64, sink chan<- *SchemaRegistryRegistered, uids []UID) (event.Subscription, error)
type UID ¶
type UID [32]byte
func HexDecodeUID ¶
func (UID) MarshalText ¶
func (*UID) UnmarshalText ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.