Reputation:
I have an oracle and JobID I’d like to submit to an oracle to get ETH price data. I have funded the node, and am following the documentation. However, every time I request the price, my BTC value will not update. The contract seems to be funded with LINK and I’m not getting gas errors, but for some reason the number will not change. What is going on?
solidity
pragma solidity ^0.6.0;
import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract testingData is ChainlinkClient {
address public owner;
uint256 public btc;
address ORACLE = 0xB36d3709e22F7c708348E225b20b13eA546E6D9c;
bytes32 constant JOB = "f9528decb5c64044b6b4de54ca7ea63e";
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
constructor() public {
setPublicChainlinkToken();
owner = msg.sender;
}
function getBTCPrice()
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
req.add("get", "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=USD&apikey=xxxx");
string[] memory copyPath = new string[](2);
copyPath[0] = "Realtime Currency Exchange Rate";
copyPath[1] = "5. Exchange Rate";
sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT);
}
function fulfill(bytes32 _requestId, uint256 _price)
public
recordChainlinkFulfillment(_requestId)
{
btc = _price;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
}
Upvotes: 4
Views: 712
Reputation: 6131
For this particular issue, do:
You need to add a multiply adapter to your job. In your getBTCPrice()
, add a line:
run.addInt("times", 100000000);
There is a full example code below, however here are some tips on what might be going on.
Fund the Ethereum address that your Chainlink node uses. You can find the address in the node Operator GUI under the Keys tab. The address of the node is the Regular type. You can obtain test ETH from several faucets.
The jobid or oracle address is wrong - double check.
The node is currently down - ask the node operator.
You are blacklisted, or not whitelisted. Contact the node operator.
In solidity, decimals don't work, so whenever you're getting a number with decimals from an oracle, you need to add a multiply adapter so that it can understand.
Whole code below:
solidity
pragma solidity ^0.6.0;
import "github.com/smartcontractkit/chainlink/evm-contracts/src/v0.6/ChainlinkClient.sol";
contract testingData is ChainlinkClient {
address public owner;
uint256 public btc;
address ORACLE = 0xB36d3709e22F7c708348E225b20b13eA546E6D9c;
bytes32 constant JOB = "f9528decb5c64044b6b4de54ca7ea63e";
uint256 constant private ORACLE_PAYMENT = 1 * LINK;
constructor() public {
setPublicChainlinkToken();
owner = msg.sender;
}
function getBTCPrice()
public
onlyOwner
{
Chainlink.Request memory req = buildChainlinkRequest(JOB, address(this), this.fulfill.selector);
req.add("get", "https://www.alphavantage.co/query?function=CURRENCY_EXCHANGE_RATE&from_currency=BTC&to_currency=USD&apikey=xxxx");
string[] memory copyPath = new string[](2);
copyPath[0] = "Realtime Currency Exchange Rate";
copyPath[1] = "5. Exchange Rate";
sendChainlinkRequestTo(ORACLE, req, ORACLE_PAYMENT);
}
function fulfill(bytes32 _requestId, uint256 _price)
public
recordChainlinkFulfillment(_requestId)
{
btc = _price;
}
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
}
Upvotes: 5