0

It's not working

function mint() public payable {
        require(
            LINK.balanceOf(address(this)) >= fee,
            "Not enough LINK - fill contract with faucet"
        );
        requestRandomness(keyHash, fee);
 }
 function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
      _safeMint(msg.sender, randomness);

 }

but it's working why?

function mint() public payable {
        require(
            LINK.balanceOf(address(this)) >= fee,
            "Not enough LINK - fill contract with faucet"
        );
        requestRandomness(keyHash, fee);
        requestToSender[requestId] = msg.sender;
    }
 function fulfillRandomness(bytes32 requestId, uint256 randomness) internal override {
      _safeMint(requestToSender[requestId], randomness);
 }

1 Answer 1

0

I'm making a few assumptions about what you mean by "not working."

Based on the code, you have a significant difference in the address you are minting to in the fulfillRandomness() function.

In the first example, you use msg.sender to mint. This is within the fulfillRandomness function; the value of this address will most likely be the address of the vrfCoordinator. This would lead to the coordinator 'owning' the NFT that you just minted.

In the second example you are mapping the address that is requesting randomness to the request ID. requestToSender[requestId] = msg.sender; and then using that mapping again in the fulfillRandomness() function. requestToSender[requestId]. This will pass the requestor's address through to the fulfillRandomness() function, leading to the original requestor 'owning' the NFT.

If it is something else that is the issue, let me know.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.