Skip to content

Commit

Permalink
Update api-staking.rst
Browse files Browse the repository at this point in the history
  • Loading branch information
svyatmikh committed Jun 10, 2019
1 parent a5259e1 commit d55216c
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions doc/api/api-staking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ The value is on the contract account and thus inaccessible to the sender.


- **function melt(uint224 val) public**
Unstake the specified value of money.
Unstake the specified value of tokens.
The value is put to the melting queue and can be withdrawn after `freezeGap`.
``Input parameter`` : "val" - value to unstake.


- **function withdraw() public**
Withdraw the previously unstaked amount of money provided the `freezeGap` time had passed since its unstake.
Withdraw the previously unstaked amount of tokens provided the `freezeGap` time had passed since its unstake.
Every 'unstake' call must match 'withdraw' call.
Takes the latest melting queue element and transfers its money amoun to the sender's account.
Takes the latest melting queue element and transfers its tokens amoun to the sender's account.


- **function getFreeMeltingSlots() view public returns (uint8)**
Expand All @@ -37,3 +37,36 @@ Every unstake call consumes a slot, every withdrawal releases it.
- **function getMeltingHead() view public returns (uint224 stake, uint32 timestamp)**
Service function, calculates the latest melting conveyer slot to bewithdrawn first.
Return Stake and timestamp pair, where stake is the amount of money unstaked and timestamp is the time of the unstake call.

API Usage Example
-----------------

Below you can see typical JS example of usage ``Bios.sol`` smartcontract.

.. code-block:: javascript
:emphasize-lines: 16, 19, 22
const gatewayUrl = 'http://148.251.152.112:18545/'; // url to the Papyrus testnet
const biosAddress = '0x142ac51e2b05a107c1482f4832b73c5bc55b6fd5'; // Address of the Bios contract in the network
const ether = 10 ** 18;
let contract;
let account;
let web3;
web3 = new Web3(window.web3.currentProvider);
const accounts = await web3.eth.getAccounts();
account = accounts[0];
const netId = await web3.eth.net.getId();
const balance = await web3.eth.getBalance(account);
contract = new web3.eth.Contract(abi, biosAddress);
//lets freeze some tokens
contract.methods.freeze().send({ from: account, gas: 0, value })
//lets unfreeze some tokens
contract.methods.melt(value).send({ from: account, gas: 0 })
//After freeze gap time - lets unfreeze our tokens
contract.methods.withdraw().send({ from: account, gas: 100000 })

0 comments on commit d55216c

Please sign in to comment.