@@ -13,6 +13,7 @@ This repository contains the Ethereum Attestation Service SDK, used to interact
13
13
- [ Getting an Attestation] ( #getting-an-attestation )
14
14
- [ Creating Onchain Attestations] ( #creating-onchain-attestations )
15
15
- [ Example: Creating Onchain Attestations] ( #example-creating-onchain-attestations )
16
+ - [ Example: Creating Multi Onchain Attestations] ( #example-creating-multi-onchain-attestations )
16
17
- [ Revoking Onchain Attestations] ( #revoking-onchain-attestations )
17
18
- [ Example: Revoking Onchain Attestations] ( #example-revoking-onchain-attestations )
18
19
- [ Creating Offchain Attestations] ( #creating-offchain-attestations )
@@ -82,7 +83,7 @@ The `getAttestation` function allows you to retrieve an on-chain attestation for
82
83
#### Usage
83
84
84
85
``` javascript
85
- import { EAS } from ' @ethereum-attestation-service/eas-sdk' ;
86
+ import { EAS , NO_EXPIRATION } from ' @ethereum-attestation-service/eas-sdk' ;
86
87
87
88
const eas = new EAS (EASContractAddress);
88
89
eas .connect (provider);
@@ -117,7 +118,7 @@ Example output:
117
118
schema: ' 0x27d06e3659317e9a4f8154d1e849eb53d43d91fb4f219884d1684f86d797804a' ,
118
119
refUID: ' 0x0000000000000000000000000000000000000000000000000000000000000000' ,
119
120
time: 1671219600 ,
120
- expirationTime: 0 ,
121
+ expirationTime: NO_EXPIRATION ,
121
122
revocationTime: 1671219636 ,
122
123
recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
123
124
attester: ' 0x1e3de6aE412cA218FD2ae3379750388D414532dc' ,
@@ -144,7 +145,7 @@ The function returns a `Promise` that resolves to the UID of the newly created a
144
145
#### Example: Creating Onchain Attestations
145
146
146
147
``` javascript
147
- import { EAS , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
148
+ import { EAS , NO_EXPIRATION , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
148
149
149
150
const eas = new EAS (EASContractAddress);
150
151
eas .connect (signer);
@@ -162,7 +163,7 @@ const transaction = await eas.attest({
162
163
schema: schemaUID,
163
164
data: {
164
165
recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
165
- expirationTime: 0 ,
166
+ expirationTime: NO_EXPIRATION ,
166
167
revocable: true , // Be aware that if your schema is not revocable, this MUST be false
167
168
data: encodedData
168
169
}
@@ -175,6 +176,54 @@ console.log('New attestation UID:', newAttestationUID);
175
176
console .log (' Transaction receipt:' , transaction .receipt );
176
177
```
177
178
179
+ #### Example: Creating Multi Onchain Attestations
180
+
181
+ ``` javascript
182
+ import { EAS , NO_EXPIRATION , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
183
+
184
+ const eas = new EAS (EASContractAddress);
185
+ eas .connect (signer);
186
+
187
+ // Initialize SchemaEncoder with the schema string
188
+ const schemaEncoder = new SchemaEncoder (' uint256 eventId, uint8 voteIndex' );
189
+ const encodedData = schemaEncoder .encodeData ([
190
+ { name: ' eventId' , value: 1 , type: ' uint256' },
191
+ { name: ' voteIndex' , value: 1 , type: ' uint8' }
192
+ ]);
193
+ const encodedData2 = schemaEncoder .encodeData ([
194
+ { name: ' eventId' , value: 10 , type: ' uint256' },
195
+ { name: ' voteIndex' , value: 2 , type: ' uint8' }
196
+ ]);
197
+
198
+ const schemaUID = ' 0xb16fa048b0d597f5a821747eba64efa4762ee5143e9a80600d0005386edfc995' ;
199
+
200
+ const transaction = await eas .multiAttest ([
201
+ {
202
+ schema: schemaId,
203
+ data: [
204
+ {
205
+ recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
206
+ expirationTime: NO_EXPIRATION ,
207
+ revocable: true , // Be aware that if your schema is not revocable, this MUST be false
208
+ data: encodedData
209
+ },
210
+ {
211
+ recipient: ' 0xA1207F3BBa224E2c9c3c6D5aF63D0eb1582Ce587' ,
212
+ expirationTime: NO_EXPIRATION ,
213
+ revocable: false ,
214
+ data: encodedData2
215
+ }
216
+ ]
217
+ }
218
+ ]);
219
+
220
+ const newAttestationUID = await transaction .wait ();
221
+
222
+ console .log (' New attestation UID:' , newAttestationUID);
223
+
224
+ console .log (' Transaction receipt:' , transaction .receipt );
225
+ ```
226
+
178
227
### Revoking Onchain Attestations
179
228
180
229
The ` revoke ` function allows you to revoke an on-chain attestation. This function takes an object with the following properties:
@@ -203,7 +252,7 @@ To create an offchain attestation, you can use the `signOffchainAttestation` fun
203
252
#### Example: Creating Offchain Attestations
204
253
205
254
``` javascript
206
- import { EAS , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
255
+ import { EAS , NO_EXPIRATION , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
207
256
208
257
// Initialize EAS with the EAS contract address on whichever chain where your schema is defined
209
258
const eas = new EAS (EASContractAddress);
@@ -225,7 +274,7 @@ const signer = new ethers.Wallet(privateKey, provider);
225
274
const offchainAttestation = await offchain .signOffchainAttestation (
226
275
{
227
276
recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
228
- expirationTime: 0n , // Unix timestamp of when attestation expires (0 for no expiration)
277
+ expirationTime: NO_EXPIRATION , // Unix timestamp of when attestation expires (0 for no expiration)
229
278
time: BigInt (Math .floor (Date .now () / 1000 )), // Unix timestamp of current time
230
279
revocable: true , // Be aware that if your schema is not revocable, this MUST be false
231
280
schema: ' 0xb16fa048b0d597f5a821747eba64efa4762ee5143e9a80600d0005386edfc995' ,
@@ -265,7 +314,7 @@ The function returns a `Promise` that resolves to the UID of the newly created a
265
314
#### Example: Creating Delegated Onchain Attestations
266
315
267
316
``` javascript
268
- import { EAS , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
317
+ import { EAS , NO_EXPIRATION , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
269
318
270
319
const eas = new EAS (EASContractAddress);
271
320
@@ -290,11 +339,11 @@ const response = await delegated.signDelegatedAttestation(
290
339
{
291
340
schema: ' 0xb16fa048b0d597f5a821747eba64efa4762ee5143e9a80600d0005386edfc995' ,
292
341
recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
293
- expirationTime: 0n , // Unix timestamp of when attestation expires (0 for no expiration)
342
+ expirationTime: NO_EXPIRATION , // Unix timestamp of when attestation expires (0 for no expiration)
294
343
revocable: true ,
295
344
refUID: ' 0x0000000000000000000000000000000000000000000000000000000000000000' ,
296
345
data: encodedData,
297
- deadline: 0n , // Unix timestamp of when signature expires (0 for no expiration)
346
+ deadline: NO_EXPIRATION , // Unix timestamp of when signature expires (0 for no expiration)
298
347
value: 0n
299
348
},
300
349
signer
@@ -304,7 +353,7 @@ const transaction = await eas.attestByDelegation({
304
353
schema: ' 0xb16fa048b0d597f5a821747eba64efa4762ee5143e9a80600d0005386edfc995' ,
305
354
data: {
306
355
recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
307
- expirationTime: 0n , // Unix timestamp of when attestation expires (0 for no expiration),
356
+ expirationTime: NO_EXPIRATION , // Unix timestamp of when attestation expires (0 for no expiration),
308
357
revocable: true ,
309
358
refUID: ' 0x0000000000000000000000000000000000000000000000000000000000000000' ,
310
359
data: encodedData
@@ -476,46 +525,43 @@ const attestation = {
476
525
// your offchain attestation
477
526
sig: {
478
527
domain: {
479
- name: " EAS Attestation" ,
480
- version: " 0.26" ,
528
+ name: ' EAS Attestation' ,
529
+ version: ' 0.26' ,
481
530
chainId: 1 ,
482
- verifyingContract: " 0xA1207F3BBa224E2c9c3c6D5aF63D0eb1582Ce587" ,
531
+ verifyingContract: ' 0xA1207F3BBa224E2c9c3c6D5aF63D0eb1582Ce587'
483
532
},
484
- primaryType: " Attest" ,
533
+ primaryType: ' Attest' ,
485
534
types: {
486
- Attest: [],
535
+ Attest: []
487
536
},
488
537
signature: {
489
- r: " " ,
490
- s: " " ,
491
- v: 28 ,
538
+ r: ' ' ,
539
+ s: ' ' ,
540
+ v: 28
492
541
},
493
- uid: " 0x5134f511e0533f997e569dac711952dde21daf14b316f3cce23835defc82c065" ,
542
+ uid: ' 0x5134f511e0533f997e569dac711952dde21daf14b316f3cce23835defc82c065' ,
494
543
message: {
495
544
version: OffchainAttestationVersion .Version2 ,
496
- schema: " 0x27d06e3659317e9a4f8154d1e849eb53d43d91fb4f219884d1684f86d797804a" ,
497
- refUID: " 0x0000000000000000000000000000000000000000000000000000000000000000" ,
545
+ schema: ' 0x27d06e3659317e9a4f8154d1e849eb53d43d91fb4f219884d1684f86d797804a' ,
546
+ refUID: ' 0x0000000000000000000000000000000000000000000000000000000000000000' ,
498
547
time: 1671219600 ,
499
- expirationTime: 0 ,
500
- recipient: " 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165" ,
501
- attester: " 0x1e3de6aE412cA218FD2ae3379750388D414532dc" ,
548
+ expirationTime: NO_EXPIRATION ,
549
+ recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
550
+ attester: ' 0x1e3de6aE412cA218FD2ae3379750388D414532dc' ,
502
551
revocable: true ,
503
- data: " 0x0000000000000000000000000000000000000000000000000000000000000000" ,
504
- },
552
+ data: ' 0x0000000000000000000000000000000000000000000000000000000000000000'
553
+ }
505
554
},
506
- signer: " 0x1e3de6aE412cA218FD2ae3379750388D414532dc" ,
555
+ signer: ' 0x1e3de6aE412cA218FD2ae3379750388D414532dc'
507
556
};
508
557
509
558
const EAS_CONFIG: OffchainConfig = {
510
559
address: attestation .sig .domain .verifyingContract ,
511
560
version: attestation .sig .domain .version ,
512
- chainId: attestation .sig .domain .chainId ,
561
+ chainId: attestation .sig .domain .chainId
513
562
};
514
563
const offchain = new Offchain (EAS_CONFIG , OffchainAttestationVersion .Version2 );
515
- const isValidAttestation = offchain .verifyOffchainAttestationSignature (
516
- attestation .signer ,
517
- attestation .sig
518
- );
564
+ const isValidAttestation = offchain .verifyOffchainAttestationSignature (attestation .signer , attestation .sig );
519
565
```
520
566
521
567
### Registering a Schema
@@ -644,7 +690,7 @@ console.log('Is Full Tree Valid?', calculatedRoot === fullTree.root);
644
690
Here's an example of how you might use the ` PrivateData ` class in conjunction with the EAS SDK to create an attestation with private data:
645
691
646
692
``` typescript
647
- import { EAS , MerkleValue , PrivateData , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
693
+ import { EAS , NO_EXPIRATION , MerkleValue , PrivateData , SchemaEncoder } from ' @ethereum-attestation-service/eas-sdk' ;
648
694
import { ethers } from ' ethers' ;
649
695
650
696
// Initialize EAS
@@ -674,7 +720,7 @@ const transaction = await eas.attest({
674
720
schema: schemaUID ,
675
721
data: {
676
722
recipient: ' 0xFD50b031E778fAb33DfD2Fc3Ca66a1EeF0652165' ,
677
- expirationTime: 0 ,
723
+ expirationTime: NO_EXPIRATION ,
678
724
revocable: true ,
679
725
data: encodedData
680
726
}
0 commit comments