🏢CompanyProfile.sol

ERC-721 Token: containing compiled empirical data about queried company

ComapnyProfile.sol

  • Allows for unique tokens that can represent individual profiles. The NFT contains metadata linking to off-chain data storage (IPFS) where the researched information and values are securely stored

  • Researched information and values

  • This NFT simply points to data stored on IPFS


CompanyProfile.sol

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

import "@openzeppelin/contracts/access/Ownable.sol";
import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol";

contract CompanyProfile is Ownable, ChainlinkClient {
    using Chainlink for Chainlink.Request;
    
    struct Company {
        string name;
        string details;
    }

    mapping(address => Company) public companies;
    mapping(bytes32 => address) private requestToCompany;

    address private oracle;
    bytes32 private jobId;
    uint256 private fee;

    event CompanyRegistered(address indexed companyAddress, string name, string details);

    constructor(address _oracle, bytes32 _jobId, uint256 _fee, address _link) {
        setChainlinkToken(_link);
        oracle = _oracle;
        jobId = _jobId;
        fee = _fee;
    }

    function requestCompanyDetails(address companyAddress, string memory name) public onlyOwner returns (bytes32 requestId) {
        Chainlink.Request memory request = buildChainlinkRequest(jobId, address(this), this.fulfillCompanyDetails.selector);
        request.add("company", name);
        requestId = sendChainlinkRequestTo(oracle, request, fee);
        requestToCompany[requestId] = companyAddress;
    }

    function fulfillCompanyDetails(bytes32 _requestId, bytes memory _details) public recordChainlinkFulfillment(_requestId) {
        address companyAddress = requestToCompany[_requestId];
        string memory details = string(_details);
        companies[companyAddress] = Company({
            name: companies[companyAddress].name,
            details: details
        });

        emit CompanyRegistered(companyAddress, companies[companyAddress].name, details);
    }

    function registerCompany(address companyAddress, string memory name) public onlyOwner {
        companies[companyAddress] = Company(name, "");
        requestCompanyDetails(companyAddress, name);
    }

    function getCompany(address companyAddress) public view returns (string memory, string memory) {
        Company memory company = companies[companyAddress];
        return (company.name, company.details);
    }
}
// i on you reviews - rosalone_labs

To achieve the goal of auto-filling the company profile from the results of the OpenAI API call when users search for business details, we need to integrate Chainlink to fetch the data from an external API (such as OpenAI) and then update the smart contract with that data. This will involve a bit more complexity as we need to handle asynchronous data fetching in a blockchain context.

Detailed Explanation

  1. Imports:

    • @openzeppelin/contracts/access/Ownable.sol: Provides ownership functionality.

    • @chainlink/contracts/src/v0.8/ChainlinkClient.sol: Provides Chainlink client functionality for interacting with external adapters.

  2. Struct and Mappings:

    • Company: Struct to store company name and details.

    • companies: Mapping from address to Company.

    • requestToCompany: Mapping from Chainlink request ID to company address.

  3. Chainlink Variables:

    • oracle, jobId, fee: Variables to store Chainlink oracle, job ID, and fee.

  4. Constructor:

    • Initializes the contract with Chainlink oracle details and sets the LINK token address.

  5. requestCompanyDetails Function:

    • Builds and sends a Chainlink request to fetch company details from an external API.

    • Maps the request ID to the company address.

  6. fulfillCompanyDetails Function:

    • Callback function to handle the response from the Chainlink oracle.

    • Updates the company details in the contract.

  7. registerCompany Function:

    • Registers a new company with its name and initiates a request to fetch its details.

  8. getCompany Function:

    • Returns the company name and details for a given address.

Additional Considerations

  • Deploy the Chainlink Oracle and Job: Ensure that you have a Chainlink oracle and job set up to fetch the company details from the API.

  • Gas Costs: Fetching data from external APIs and writing it on-chain can be expensive. Make sure to optimize the process and handle the costs efficiently.

Last updated