-
Notifications
You must be signed in to change notification settings - Fork 0
Solidity API
async function initWeb3() {
web3 = new Web3(window.ethereum);
await $.getJSON('KuoriciniDao.json', function(data) {
KuoriciniDao = TruffleContract(data);
KuoriciniDao.setProvider(web3Provider);
});
accounts = await web3.eth.getAccounts();
instance = await KuoriciniDao.deployed();
}
now you can use instance
to call the contract methods.
Below all the methods available.
The last parameter is always , {from: accounts[0]}
, which I don't consider in this list.
- write functions require spending, and return nothing if they worked, or return a Metamask error if they didn't work
- read functions don't require spending, no Metamask approval, and always return something
read
returns the name of address
user.name = await instance.nameOf(user.address, {from: accounts[0]});
write
sets the username
read
returns the list of the ID of the groups of the user
let myg = await instance.myGroups({from: accounts[0]});
read
returns the object of a Group id
- string name (name of the group)
- string[] members (array of strings of members addresses)
- uint[] tokenIds (array of ID of tokens of the group)
- uint[] candidateIds ( not used - obsolete )
- uint[] candidateTokenIds (array of ID of candidates tokens, users, quorums that need voting, use )
- uint voteThreshold (vote threshold of the group DAO)
- string invitationLink (group invitation link string)
write
create a new group
write
remove current user from groupID
read
returns the array of objects of all the tokens of a user (in a specific group) Array of:
- uint tokenID (ID of the Group Token)
- uint gTokenBalance (total balance of tokens accumulated by the user)
- uint xBalance (balance of tokens remaining to spend in the period)
read
returns object properties of the token with specific ID:
- string name (token name)
- uint roundSupply (how many tokens available for each round)
- uint roundDuration (how long is the round in seconds)
- uint timestamp (previous marked period - obsolete)
write
sends count number of tokens from the current user to receiver address returns true Array of:
- uint tokenId (ID of the Group Token)
- uint gTokenBalance (total balance of tokens accumulated by the user)
- uint xBalance (balance of tokens remaining to spend in the period)
write
The most complex method in KuoriciniDAO. All changes proposal are created with this token. Note is called changeToken but is the same to propose any candidate, depending on candtype: Note input parameters can have different values depending on which candtype!
candtype can be
0 : new address (candidate new address in a group)
1 : new token (candidate a new token)
2 : change existing token
3 : new quorum
- uint value always 0
- string name is the group invitation Link
- uint supply always 0
- uint duration always 0
- uint groupid is the group to candidate the user
- uint value always 0
- string name, candidate name of the token
- uint supply, candidate supply for period
- uint duration, candidate duration of the period
- uint groupid, groupID for which the token is candidate
- uint value, tokenID to change
- string name, candidate name of the token
- uint supply, candidate supply for period
- uint duration, candidate duration of the period
- uint groupid, groupID for which the token is candidate
- uint value, value of the quorum from 1 (10%) to 10 (100%)
- string name, always empty
- uint supply, always 0
- uint duration, always 0
- uint groupid, groupID for which propose a new qorum
read
Get candidates array of objects to be voted Array of:
- uint id, candidate token ID if candType==2, threshold value if candType==3
- uint candType, 0,1,2,3 see method
changeToken
- string name, token name if candType is 1 or 2
- uint roundSupply, token supply if candType is 1 or 2
- uint roundDuration, token duration if candType is 1 or 2
- address candidateAddress, candidate address if candType is 0
- uint votes, number of votes up to now
- address[] voters, address of voters (will change)
write
Votes for a candidate Token.
- groupid, group id
- candidateTokenId, candidate token ID to vote
- uint vote, vote can be > 1 (positive) or 0 (not positive)
read
returns 0 if link is invalid, id of a group >0 if link is invitation of a group
- uint the id of the group invited. If 0, the link is not valid
read
If you are not part of a group, you cannot call getGroup. So you need this function which returns the group name using the invitation link.
- string name