I am trying to call to an BSC Oracle to make an HTTP request according this ChainLink example. In my example I am goin to use the BSC mainnet 56 and a other JobID obviously:
My steps:
I created the contract with this zenAPIs get request contract and jobID over the BSC Mainnet:
I deployed the contract to the BSC Mainnet. There was an error, but the contract seems created.
I funded the contract with ERC677 LINK and the BSC accepted it. (I used this Chainlink official swap for change the Binance sent links to my wallet: https://pegswap.surge.sh/)
I called the requestEthereumPrice() function and the BSC return OK.
I get the "currentPrice" var and REMIX return this error:
"Failed to decode output: Error: data out-of-bounds (length=0, offset=32, code=BUFFER_OVERRUN, version=abi/5.0.7)"
The contract:
/**
* Network: Binance Smart Chain - Mainnet
* ZenApis. Job: HTTP get:
* https://market.link/nodes/fd5a3998-75bb-4705-9f34-b51f02ed5f0e?network=56
* https://market.link/jobs/5ddd8a96-8840-4b55-9163-f07674c8c004/spec?network=56
* Oracle: 0x074715cc07fC0Df9c617F22971Fb2Ff1b1f57278
* Job ID: c734c40b377544f08a7324f36bda4940 //https://market.link/jobs/5ddd8a96-8840-4b55-9163-f07674c8c004/spec?network=56
* Fee: 0.02 LINK
* LINK Token Address: 0x404460c6a5ede2d891e8297795264fde62adbb75
*
* Video tutorial: https://www.youtube.com/watch?v=AtHp7me2Yks
*/
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.6.0;
import "https://raw.githubusercontent.com/smartcontractkit/chainlink/develop/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract ChainlinkExample is ChainlinkClient {
// Stores the answer from the Chainlink oracle
uint256 public currentPrice;
address public owner;
address ORACLE_ADDRESS = 0x074715cc07fC0Df9c617F22971Fb2Ff1b1f57278;
string constant JOBID = "c734c40b377544f08a7324f36bda4940";
uint256 constant private ORACLE_PAYMENT = 20000000000000000;// 16 0s = 0.02 LINK
constructor() public {
// Set the address for the LINK token for the network
setPublicChainlinkToken();
owner = msg.sender;
}
// Creates a Chainlink request with the uint256 multiplier job
function requestEthereumPrice() public onlyOwner{
Chainlink.Request memory req = buildChainlinkRequest(stringToBytes32(JOBID), address(this), this.fulfill.selector);
req.add("get", "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD");//{"USD":1797.12}
req.add("path", "USD");
req.addInt("times", 100);
sendChainlinkRequestTo(ORACLE_ADDRESS, req, ORACLE_PAYMENT);
}
// fulfill receives a uint256 data type
function fulfill(bytes32 _requestId, uint256 _price) public recordChainlinkFulfillment(_requestId) { // Use recordChainlinkFulfillment to ensure only the requesting oracle can fulfill
currentPrice = _price;
}
// cancelRequest allows the owner to cancel an unfulfilled request
function cancelRequest(bytes32 _requestId, uint256 _payment, bytes4 _callbackFunctionId, uint256 _expiration) public onlyOwner {
cancelChainlinkRequest(_requestId, _payment, _callbackFunctionId, _expiration);
}
// withdrawLink allows the owner to withdraw any extra LINK on the contract
function withdrawLink() public onlyOwner{
LinkTokenInterface link = LinkTokenInterface(chainlinkTokenAddress());
require(link.transfer(msg.sender, link.balanceOf(address(this))), "Unable to transfer");
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
// A helper funciton to make the string a bytes32
function stringToBytes32(string memory source) private pure returns (bytes32 result) {
bytes memory tempEmptyStringTest = bytes(source);
if (tempEmptyStringTest.length == 0) {
return 0x0;
}
assembly { // solhint-disable-line no-inline-assembly
result := mload(add(source, 32))
}
}
}