Skip to content

Solidity API

Fabian Chawin Cedrati edited this page Jun 26, 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)
  • uint voteThreshold (vote threshold of the group DAO)
  • string invitationLink (group invitation link string)

createGroup(string name)

write

create a new group returns true

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(string link)

read

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

Clone this wiki locally