我一直在尝试将 Chainlink 集成到我的合同中,设法让随机数起作用,但 API 调用对我不起作用。这是我得到的:
contract ValorantCards is Ownable, ERC1155, VRFConsumerBase, ChainlinkClient {
using Chainlink for Chainlink.Request;
address private linkToken;
// Chainlink VRF
bytes32 private keyHash;
uint256 private vrfFee;
uint256 public randomResult;
// Chainlink API calls
address private oracle;
bytes32 private jobId;
uint256 private oracleFee;
uint256 public playerLevel;
constructor(
address _vrfCoordinator,
address _linkToken,
bytes32 _keyHash,
address _oracle,
bytes32 _jobId,
uint256 _oracleFee
) ERC1155("") VRFConsumerBase(_vrfCoordinator, _linkToken) {
setPublicChainlinkToken();
linkToken = _linkToken;
keyHash = _keyHash;
vrfFee = 0.1 * 10**18;
oracle = _oracle;
jobId = _jobId;
oracleFee = _oracleFee;
}
function requestUserLevel() public returns (bytes32 requestId) {
Chainlink.Request memory request = buildChainlinkRequest(
jobId,
address(this),
this.fulfill.selector
);
request.add(
"get",
"https://api.henrikdev.xyz/valorant/v1/account/draven/2023"
);
request.add("path", "data.account_level");
return sendChainlinkRequestTo(oracle, request, oracleFee);
}
function fulfill(bytes32 _requestId, uint256 _level)
public
recordChainlinkFulfillment(_requestId)
{
playerLevel = _level;
}
我正在使用以下参数从安全帽进行部署(忽略 VRF 的参数,因为它有效):
甲骨文:0x9C0383DE842A3A0f403b0021F6F85756524d5599
JobId:0x3766623533366265383635623433333662323766633130313437633139336337
甲骨文费用:0.1 * 10**18
该函数运行良好,事务没有恢复或任何东西,但是当我检查“playerLevel”时,它总是只有 0
希望各位大神能帮帮忙,先谢谢了!