Skip to content

Commit

Permalink
Merge pull request #2 from papyrusglobal/denis/bios-location
Browse files Browse the repository at this point in the history
Denis/bios location
  • Loading branch information
svyatmikh committed Nov 10, 2019
2 parents 67e78ae + 91721e0 commit 97b18b5
Showing 1 changed file with 45 additions and 29 deletions.
74 changes: 45 additions & 29 deletions doc/api/api-bios.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,60 @@ Latest version of the Bios contact you can always `find in our repo <https://gi
BIOS Addresses
--------------

Testnet BIOS address : `0x8f98d0aa9b01e7d15a7950db68b26b89d6f1be14 <http://explorer-testnet.papyrus.network/addr/0x8f98d0aa9b01e7d15a7950db68b26b89d6f1be14#tab_addr_1>`_
To track the current address of the Bios contract, there is a `Versioner <https://github.com/papyrusglobal/papyrus/blob/master/papyrus-stuff/contracts/Versioner.sol>`_ contract located at fixed address :code:`0x0000000000000000000000000000000000000022`. To query it for the Bios contract address, use `bios` public method. Here is an example in javascript:

Testnet `BIOS Abi <https://github.com/papyrusglobal/explorer/blob/master/abi/bios.json>`_
.. code-block:: javascript
const versionerAbi = [
{
constant: true,
inputs: [],
name: 'bios',
outputs: [{ name: '', type: 'address' }],
payable: false,
stateMutability: 'view',
type: 'function'
}
];
const versionerAddress = '0x0000000000000000000000000000000000000022';
const versioner = new web3.eth.Contract(versionerAbi, versionerAddress);
const biosAddress = await versioner.methods.bios().call({ from: account });
Note that the resulting address may be zero, this means that the Bios contract is not yet installed.

BIOS Usages examples
--------------------

Let's take a look at the simple example of Javascript code that will get all authorities nodes from our BIOS contract.
Let's take a look at the simple example of Javascript code that will get all authorities nodes from our BIOS contract.

.. code-block:: javascript
:emphasize-lines: 2, 7, 15
const { eth } = require('./web3relay');
const ABI = require('../abi/bios');
const { getConfig } = require('../utils');
const config = getConfig();
if (!config.biosAddress) throw new Error('Setup config.biosAddres');
const contract = new eth.Contract(ABI, config.biosAddress);
module.exports = function (req, res) {
if (typeof contract.methods.getAuthorities !== 'function') {
console.error('Contract method \'getAuthorities\' not found', err);
res.send([]);
res.end();
}
contract.methods.getAuthorities().call()
.then(authorities => {
res.send(authorities);
res.end();
})
.catch(err => {
console.error('Can\'t get authorities from contract. Silently return empty array', err);
res.send([]);
res.end();
})
};
const { eth } = require('./web3relay');
const ABI = require('../abi/bios');
const { getConfig } = require('../utils');
const config = getConfig();
if (!config.biosAddress) throw new Error('Setup config.biosAddres');
const contract = new eth.Contract(ABI, config.biosAddress);
module.exports = function (req, res) {
if (typeof contract.methods.getAuthorities !== 'function') {
console.error('Contract method \'getAuthorities\' not found', err);
res.send([]);
res.end();
}
contract.methods.getAuthorities().call()
.then(authorities => {
res.send(authorities);
res.end();
})
.catch(err => {
console.error('Can\'t get authorities from contract. Silently return empty array', err);
res.send([]);
res.end();
})
};
If you are interested to see more examples how to call BIOS contact API you could check our API documentation sections for example - `Voting API <https://papyrus-network.readthedocs.io/en/latest/doc/api/api-staking.html#api-usage-example>`_
If you are interested to see more examples how to call BIOS contact API you could check our API documentation sections for example - `Voting API <https://papyrus-network.readthedocs.io/en/latest/doc/api/api-staking.html#api-usage-example>`_

0 comments on commit 97b18b5

Please sign in to comment.