0

I tried to deploy this solidity code on Remix

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

// Import ChainlinkClient from the Chainlink library
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

contract EmailVerification is ChainlinkClient {
    using Chainlink for Chainlink.Request;
    address public owner;
    bytes32 public jobId;
    uint256 public fee;
    string public emailServiceURL;
    string public apiKey;

    event VerificationRequested(address indexed user, string email);
    event VerificationCompleted(address indexed user);

    constructor() {
        setPublicChainlinkToken();
        setChainlinkOracle(0x40193c8518BB267228Fc409a613bDbD8eC5a97b3);
        jobId = '7da2702f37fd48e5b1b9a5715e3509b6';
        fee = (1 * LINK_DIVISIBILITY) / 10;
        emailServiceURL = 'url';
        apiKey = 'my-api-key';
        owner = msg.sender;
    }

    function requestVerification(string memory recipientEmail) public {
        Chainlink.Request memory req = buildChainlinkRequest(
            jobId,
            address(this),
            this.fulfill.selector
        );
        string memory subject = "Email Verification";
        string memory message = "Please click the verification link to confirm your email.";
        req.add("to", recipientEmail);
        req.add("subject", subject);
        req.add("message", message);
        req.add("url", emailServiceURL);
        req.add("apikey", apiKey);
        sendChainlinkRequestTo(chainlinkOracleAddress(), req, fee);
        emit VerificationRequested(msg.sender, recipientEmail);
    }

    function fulfill(bytes32 requestId) public recordChainlinkFulfillment(requestId) {
        // Handle email service response and confirm verification
        // Emit an event to signify verification completion
        emit VerificationCompleted(msg.sender);
    }

    // Helper function to convert bytes32 to string
    function bytes32ToString(bytes32 _bytes32) internal pure returns (string memory) {
        bytes memory bytesString = new bytes(32);
        uint charCount = 0;
        for (uint j = 0; j < 32; j++) {
            uint8 character = uint8(uint256(_bytes32) * uint256(2) ** (8 * j));
            if (character != 0) {
                bytesString[charCount] = bytes1(character);
                charCount++;
            }
        }
        bytes memory bytesStringTrimmed = new bytes(charCount);
        for (uint j = 0; j < charCount; j++) {
            bytesStringTrimmed[j] = bytesString[j];
        }
        return string(bytesStringTrimmed);
    }

  receive() external payable {}

     
}

But I am getting this warning message from Remix

Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending? Returned error: {"jsonrpc":"2.0","error":"execution reverted","id":1970708253356763}

And the transaction fails if I try to send it like that. I have tried increasing the gas limit but it's still not working.

Any suggestion on how to solve this issue would be greatly appreciated.

1
  • The error is coming because of setPublicChainlinkToken();. Maybe check the docs or reach out to the community. I am not free right now to figure that out. Oct 19, 2023 at 8:55

1 Answer 1

0

Use setChainlinkToken(address) instead of setPublicChainlinkToken() setChainlinkToken takes address of deployed instance of LINK token. you can find the addresses of deployed link tokens here

if you use setPublicChainlinkToken() it will use a link tokens pointer contract address which will not be deployed in your local remix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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