Minting Tokens equal to USD using API and Calculate (Burnt out noob question)

Hello All! This is a bit all over the place, I think I have stared at it too long.
Below I am using provable API and a calculate function to try and mint an ERC20 token, like for like to a senders ETH value. So $10 in Eth recieved, mints 10 ERC20 tokens.

I need the function to be 'all in one', so when called, the API gets the price, returns it, the value passes through the calculator and then the _minter sends the equivalent value in tokens. :face_with_raised_eyebrow:

Please see my mess below, i really need help on this!!

pragma solidity ^0.8.0

    function calculateTokenAmount(
        uint256 _weiAmount
        returns (uint256)
        return _weiAmount / pricePerTokenInWei;

    function converterPrice( /// merged several functions. 
    bytes32 _queryID,
    string memory _result
    public payable 
        require(msg.sender == _owner);
        require(msg.sender == provable_cbAddress());
        provable_query("URL", "json(");
        require(msg.sender == provable_cbAddress());
        ethPriceInCents = parseInt(_result, 2);
        pricePerTokenInWei = calculatePricePerTokenInWei(ethPriceInCents);
        emit LogEthPriceInCents(ethPriceInCents);
     function mint(address to, uint256 amount) public onlyOwner {
        _mint(to, amount);
    function calculatePricePerTokenInWei(
        uint256 _ethPriceInCents
        returns(uint256 _pricePerTokenInWei)
        uint256 numerator = 1 * 10 ** 20;
        return numerator / _ethPriceInCents;

What's the problem? What error do you see?

Thanks for getting back to me!

It functions well, but its heavily manual and not suitable for production if the contract were to recieve heavy volumes. Is there any way of these functions to be added into the minter, for a more automated approach? I.e it automatically executes and mints when one function is called?

I feel im missing some basic solidity principles.

I think this problem is much more about the API offered by Provable, rather than basic Solidity principles.

The code you shared looks incomplete so I can't help much.

As a side note, avoid comments like "i really need help on this!!". We already know you need help. :slight_smile: