BerryDocs
Search…
Using Berry Sample
Sample project UsingBerry
The Berry oracle is a decentralized oracle on Binance Smart Chain. It provides an option for contracts to securely interact with and obtain data from off-chain.
Quick references are included below:
Implement Berry into your project This repo already includes the usingBerry package.

How to use

1. Clone the project and install dependencies
1
git clone [email protected]:berrydata/SampleUsingBerry.git
2
npm install
Copied!
2. How to Use
Just Inherit the UsingBerry contract, passing the Berry address as a constructor argument:
Here's an example
1
contract BtcPriceContract is UsingBerry {
2
3
//This Contract now have access to all functions on UsingBerry
4
5
uint256 btcPrice;
6
uint256 btcRequetId = 1;
7
8
constructor(address payable _berryAddress) UsingBerry(_berryAddress) public {}
9
10
function setBtcPrice() public {
11
bool _didGet;
12
uint _timestamp;
13
uint _value;
14
15
(_didGet, btcPrice, _timestamp) = getCurrentValue(btcRequetId);
16
}
17
}
Copied!
Addresses:
BSC Mainnet: ``
3. The sample contract SampleUsingBerry have access to the following Berry functions:
1
/**
2
* @dev Retreive value from oracle based on requestId/timestamp
3
* @param _requestId being requested
4
* @param _timestamp to retreive data/value from
5
* @return uint value for requestId/timestamp submitted
6
*/
7
function retrieveData(uint256 _requestId, uint256 _timestamp) public view returns(uint256);
8
9
/**
10
* @dev Gets if the mined value for the specified requestId/_timestamp is currently under dispute
11
* @param _requestId to looku p
12
* @param _timestamp is the timestamp to look up miners for
13
* @return bool true if requestId/timestamp is under dispute
14
*/
15
function isInDispute(uint256 _requestId, uint256 _timestamp) public view returns(bool);
16
17
/**
18
* @dev Counts the number of values that have been submited for the request
19
* @param _requestId the requestId to look up
20
* @return uint count of the number of values received for the requestId
21
*/
22
function getNewValueCountbyRequestId(uint256 _requestId) public view returns(uint);
23
24
/**
25
* @dev Gets the timestamp for the value based on their index
26
* @param _requestId is the requestId to look up
27
* @param _index is the value index to look up
28
* @return uint timestamp
29
*/
30
function getTimestampbyRequestIDandIndex(uint256 _requestId, uint256 _index) public view returns(uint256);
31
32
/**
33
* @dev Allows the user to get the latest value for the requestId specified
34
* @param _requestId is the requestId to look up the value for
35
* @return bool true if it is able to retreive a value, the value, and the value's timestamp
36
*/
37
function getCurrentValue(uint256 _requestId) public view returns (bool ifRetrieve, uint256 value, uint256 _timestampRetrieved);
38
39
/**
40
* @dev Allows the user to get the first value for the requestId before the specified timestamp
41
* @param _requestId is the requestId to look up the value for
42
* @param _timestamp before which to search for first verified value
43
* @return bool true if it is able to retreive a value, the value, and the value's timestamp
44
*/
45
function getDataBefore(uint256 _requestId, uint256 _timestamp)
46
public
47
view
48
returns (bool _ifRetrieve, uint256 _value, uint256 _timestampRetrieved);
Copied!
5. To run tests:
1
npm run test
Copied!
6. Migrations:
Just run truffle migrate with the desired Network
1
truffle migrate
Copied!
Last modified 8mo ago
Copy link
Contents
How to use