'Remix error message 'Unused function parameter' with fulfillRandomness using Chainlink VRF Smart Contract
The issue is a repeated error message upon attempting to compile a verifiable random number smart contract in remix. This particular function (line 48 in remix or last line of code below) yields the error message consistently across compiler versions (I checked the imported documents versions too), cross brave browser+firefox, and even after checking grammar. I do not understand what this error message is conveying (I am brand new to programming) and I cannot find another thread with this same issue. I suspect the function to be faulty in some sense of how it is either defined or interacting with the other imported documents (VRFConsumerBase.sol).
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import "@chainlink/contracts/src/v0.8/VRFConsumerBase.sol";
/**
* Request testnet LINK and ETH here: https://faucets.chain.link/
* Find information on LINK Token Contracts and get the latest ETH and LINK faucets here:
* https://docs.chain.link/docs/link-token-contracts/
*/
contract RandomNumberConsumer is VRFConsumerBase {
bytes32 public keyHash;
uint256 public fee;
uint256 public randomResult;
/**
* Constructor inherits VRFConsumerBase
*
* Network: Rinkeby
* Chainlink VRF Coordinator address: 0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B
* LINK token address: 0x01BE23585060835E02B77ef475b0Cc51aA1e0709
* Key Hash: 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311
*/
constructor() VRFConsumerBase(
0xb3dCcb4Cf7a26f6cf6B120Cf5A73875B7BBc655B, //VRF Coordinator
0x01BE23585060835E02B77ef475b0Cc51aA1e0709) //Rinkeby LINK Token
{
keyHash = 0x2ed0feb3e7fd2022120aa84fab1945545a9f2ffc9076fd6156fa96eaff4c1311;
fee = 0.1 * 10 ** 18; //0.1 LINK (varies by network)
}
/**
* Requests fulfillRandomness
*/
function getRandomNumber() public returns (bytes32 requestId) {
require(LINK.balanceOf(address(this)) >= fee, "Not enough LINK - fill contract with faucet");
return requestRandomness(keyHash, fee);
}
/**
* Callback function used by VRF Coordinator
*/
function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
randomResult = randomness;
}
}
This near identical code can be found at https://docs.chain.link/docs/get-a-random-number/ (line 52). Here is the error message below,
from solidity:
Warning: Unused function parameter. Remove or comment out the variable name to silence this warning.
--> docs.chain.link/samples/VRF/RandomNumberConsumer.sol:52:32: function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
I am following the 'Getting A Random Number with Chainlink VRF' tutorial from Chainlink https://www.youtube.com/watch?v=JqZWariqh5s (timestamp @ 9:30) except I am testing on the Rinkeby network not Kovan. I also double checked with this tutorial. https://www.youtube.com/watch?v=_aXumgdpnPU (timestamp @ 12:00) Neither tutorial encounters this specific error message and both are able to compile and deploy the smart contract successfully. I also receive the error message when I directly open and attempt to compile the smart contract from the Chainlink website without touching the code.
Solution 1:[1]
i had the same error i fixed it by leaving the bytes32 parameter empty
your code (bytes32 requestId , uint256 randomness)
instead use: (bytes32, uint256 randomness)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Farah Ahmed |
