Skip to content

Solidity API

Fabian Chawin Cedrati edited this page Jul 27, 2022 · 6 revisions

Provisional Solidity API documentation

Initialization:

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

User methods

nameOf(string address)

read

returns the name of address

user.name = await instance.nameOf(user.address, {from: accounts[0]});

nameSet(string name)

write

sets the username

Group methods

myGroups()

read

returns the list of the ID of the groups of the user

let myg = await instance.myGroups({from: accounts[0]});

getGroup(uint id)

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)

createGroup(string name)

write

create a new group

removeMeFromGroup(uint groupID)

write

remove current user from groupID

Token methods

getUserTokens(uint 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)

getToken(uint tokenID)

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)

transferToken(uint tokenId, string receiverAddress, uint count)

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)

DAO Voting methods

changeToken(uint value, string name, uint supply, uint duration, uint groupid, uint candtype)

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 

if candtype==0 (candidate a new address in a group)

  • 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

if candtype==1 (candidate a new token)

  • 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

if candtype==2 (change existing token)

  • 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

if candtype==3 (new quorum)

  • 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

getGroupCandidateTokens(uint groupid)

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)

voteCandidateToken(uint groupid, uint candidateTokenId, uint vote)

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)

invitation Link methods

checkInvitationLink(string invitationlink)

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

groupNameByInvitation(uint groupid, string invitationlink)

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