-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetMember.js
49 lines (43 loc) · 1.67 KB
/
getMember.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { ethers, BigNumber, utils } from 'ethers'
export const checkSignature = (message, signature) => {
const msgHash = utils.hashMessage(message)
const msgHashBytes = utils.arrayify(msgHash)
const account = utils.recoverAddress(msgHashBytes, signature)
return account.toLowerCase() || ''
}
export default async function getMember() {
//Need to add 'Please switch to the approripate network' if not xDai
const provider = new ethers.providers.Web3Provider(window.ethereum)
// Prompt user for account connections
//let result = await provider.send('eth_requestAccounts', [])
//console.log('The address is ', result[0])
const signer = provider.getSigner()
const userAddress = await signer.getAddress()
const message = 'Sign here.'
const signature = await signer.signMessage(message)
const accountFromSignature = checkSignature(message, signature)
console.log('Account from signature is ', accountFromSignature)
const contractAddress = '0xD83AC7D30495e1E1d2f42a0D796a058089719a45'
const abi = [
{
type: 'function',
stateMutability: 'view',
payable: false,
outputs: [
{ type: 'address', name: 'delegateKey' },
{ type: 'uint256', name: 'shares' },
{ type: 'uint256', name: 'loot' },
{ type: 'bool', name: 'exists' },
{ type: 'uint256', name: 'highestIndexYesVote' },
{ type: 'uint256', name: 'jailed' },
],
name: 'members',
inputs: [{ type: 'address', name: '' }],
constant: true,
},
]
const contract = new ethers.Contract(contractAddress, abi, provider)
const memberData = await contract.members(userAddress)
const existence = memberData.exists
return existence
}