File tree Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Expand file tree Collapse file tree 3 files changed +42
-2
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @snapshot-labs/snapshot.js" ,
3
- "version" : " 0.11.12 " ,
3
+ "version" : " 0.11.13 " ,
4
4
"repository" : " snapshot-labs/snapshot.js" ,
5
5
"license" : " MIT" ,
6
6
"main" : " dist/snapshot.cjs.js" ,
Original file line number Diff line number Diff line change @@ -97,7 +97,7 @@ export default class Client {
97
97
if ( res . ok ) return resolve ( res . json ( ) ) ;
98
98
throw res ;
99
99
} )
100
- . catch ( ( e ) => e . json ( ) . then ( ( json ) => reject ( json ) ) ) ;
100
+ . catch ( ( e ) => reject ( e ) ) ;
101
101
} ) ;
102
102
}
103
103
Original file line number Diff line number Diff line change
1
+ <!-- This is a simple example of how to use snapshot.js to vote using a web3 provider -->
2
+ <!-- serve -p 9000 -->
3
+ <!-- Go to http://localhost:9000/test/test.html -->
4
+ < script src ="../dist/snapshot.min.js "> </ script >
5
+ < script src ="https://cdn.ethers.io/lib/ethers-5.6.umd.min.js " type ="text/javascript ">
6
+ </ script >
7
+
8
+
9
+
10
+ < button id ="connectButton "> Connect</ button >
11
+ < button id ="voteButton "> Vote</ button >
12
+
13
+ < script >
14
+ const hub = 'http://localhost:3001' ; // or https://testnet.hub.snapshot.org for testnet
15
+ const client = new snapshot . Client712 ( hub ) ;
16
+
17
+ // Connect to Ethereum wallet
18
+ document . getElementById ( "connectButton" ) . addEventListener ( "click" , async ( ) => {
19
+ await window . ethereum . request ( { method : 'eth_requestAccounts' } ) ;
20
+ console . log ( 'Connected to wallet' , await window . ethereum . request ( { method : 'eth_accounts' } ) ) ;
21
+ } ) ;
22
+
23
+ // Vote using snapshot.js
24
+ document . getElementById ( "voteButton" ) . addEventListener ( "click" , async ( ) => {
25
+ const web3 = new ethers . providers . Web3Provider ( window . ethereum ) ;
26
+ const [ account ] = await web3 . listAccounts ( ) ;
27
+ try {
28
+ const receipt = await client . vote ( web3 , account , {
29
+ space : 'yam.eth' ,
30
+ proposal : '0x21ea31e896ec5b5a49a3653e51e787ee834aaf953263144ab936ed756f36609f' ,
31
+ type : 'single-choice' ,
32
+ choice : 1 ,
33
+ reason : 'Choice 1 make lot of sense' ,
34
+ app : 'my-app'
35
+ } ) ;
36
+ } catch ( error ) {
37
+ console . log ( 'catched an error' , error ) ;
38
+ }
39
+ } ) ;
40
+ </ script >
You can’t perform that action at this time.
0 commit comments