-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgetMember.js
More file actions
50 lines (43 loc) · 1.75 KB
/
Copy pathgetMember.js
File metadata and controls
50 lines (43 loc) · 1.75 KB
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
50
import { ethers, BigNumber } from 'ethers';
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();
//Is this method of getting address sufficient, or can it be faked?
const userAddress = await signer.getAddress();
//const userAddress = '0x9bcDc7db2f57B0f960A737ccC29373a9bc760134'; //CPTNSkeletor's address
//const userAddress = '0x0b5f5a722ac5e8ecedf4da39a656fe5f1e76b34d'; //non-member
/*const signature = await signer.signMessage('Sign here.');
console.log('Signature output:', signature);
*/
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);
//Method 1: Return share count as a number
const shares = BigNumber.from(memberData[1]).toNumber();
return shares;
/* //Method 2: Return 'exists' value as a boolean
const existence = memberData.exists;
return existence; */
}