I want to set the price in Token every time the contract is deployed by calling ETHUSD in constructor and getting result from it.

pragma solidity ^0.5.0;

import "./ETHUSD.sol";

contract Token {

    uint256 public price;

    constructor() public {
        price =

What should I add in Token after "price =" to make it work?

pragma solidity ^0.5.0;

    import "./oraclizeAPI.sol";

    contract ETHUSD is usingOraclize {

        string public priceETHUSD;

        event LogNewCoinBaseOraclizeQuery(string description);
        event LogNewCoinBaseTicker(string price);

        constructor() public {
            oraclize_setProof(proofType_Android | proofStorage_IPFS);
            update(); // Update price on contract creation...

        function __callback(bytes32 _myid, string memory _result, bytes memory _proof) public {
            require(msg.sender == oraclize_cbAddress());
            update(); // Recursively update the price stored in the contract...
            priceETHUSD = _result;
            emit LogNewCoinBaseTicker(priceETHUSD);

        function update() public payable {
            if (oraclize_getPrice("URL") > address(this).balance) {
                emit LogNewCoinBaseOraclizeQuery("Oraclize query was NOT sent, please add some ETH to cover for the query fee!");
            } else {
                emit LogNewCoinBaseOraclizeQuery("Oraclize query was sent, standing by for the answer...");
                oraclize_query(5, "URL", "json(https://api.pro.coinbase.com/products/ETH-USD/ticker).price");

Contract above ETHUSD is just example and it gets the price from the API.

price = ETHUSD(0x123abc...).priceETHUSD();

Replace 0x123abc... with the actual address of the deployed ETHUSD contract you want to use.

  • That's what I was looking for, thank you.
    – 3rr0r
    Jun 10 '19 at 13:44
  • Should go ahead and accept that answer @3rr0r
    – foba
    Jun 12 '19 at 23:19


That’s works and it’s gets the specific price from the „0x123abc...” address contract.

But how I can get „0x123abc...” address field automatically updated every time I call the Token contract?

What I mean by that that is:

Token => call ETHUSD => ETHUSD is deployed and new address is generated => Token

price = ETHUSD(new address).priceETHUSD();

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.