Latest 25 txns

TxHash Age From To Value [TxFee]
0x5bfb6bbdf821108ff0c97fb730003c35ae6cf14a0eb2e12fe360f739616a8abe8 days 12 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xd48f395a7603787013213d60787daeca832de95bd283a23386eba6b0e340f8678 days 16 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x3f51ef2cc02aed16a482e32de71335f76fba2b3a5d5f1f17fb19fc39489816648 days 17 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x60b98835441c944431aea216027dbf7ae62e53b6d5f9a3b62b9801dbb8d9820a11 days 18 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x0ae21340a2d13bcec9b85137db3fee39e5661ada51fe20cf5926242d2421d6c211 days 19 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x8f8efad22f198f201085b11b94524551902ce269eb6028d13d2a8affd3dc346511 days 19 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xf51f095818c688f32e17ae124cf8c155c257e131ebacc70ce6a10f5b632f9c0d11 days 19 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x5cc1f1c1856716a8b7dd0d0ff9a1f8a61daa05a2d24e0e8ddc98a8b2ee9ff79612 days 15 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x8840460761114ce4ddb5944d4dddaa165d5ac9a23a26c533e62fae2ec2f848b612 days 15 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x75c329daff3fadf0e725756457c6c01048ecf088fbfd4a7c9f0c08c43e3eb66812 days 15 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.000872152
0xe23ae7f7cc1008f6c34bf84953f1ecbed91f3ed624de9cb5d3ae01ad4389b39a13 days 1 hr ago0xaec1f213677de24842a96e72fe6efbcbc2b77ca5  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xd1188cbfd6defd4b4207e3cb6fabb2363a36251ba68dd65db28c708ddbfee99913 days 1 hr ago0xaec1f213677de24842a96e72fe6efbcbc2b77ca5  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x27172ba2ae7cc1bd93965e478d8fba06f062591addb9ea2b64e12a6d43dd55ab13 days 1 hr ago0xaec1f213677de24842a96e72fe6efbcbc2b77ca5  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xa849a25c95791ecc6700148d5253e1cbc435a59c1320692d3cdc26847485a57c13 days 1 hr ago0xaec1f213677de24842a96e72fe6efbcbc2b77ca5  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x7bb98b226aa15ca9558738b2618f78f9be5f71f6a54d5ec7a8a6c62676cdb12513 days 18 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.001033206
0xb3d15be2d7550745ad10f9bd14f8c228f55f55e3bf21b1df8349ea08704ab0af13 days 18 hrs ago0xe222f441cb42bcfe8e46fdecad0e633c70246bd3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.001033206
0xb366bb27fbdc914fb6bca95e4893e852f69139c42ae1f3b2d2d57294442d7f9413 days 18 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xd5d0d63c221679940834ec709011bf9deeddde8c073503c9e9683907d65a8db113 days 19 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xa0d7f731dba4b0f7b1f5f2a9faf2a64de4d2e12b6615e8cd7ec42b31d5647aaf13 days 19 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xa2988a32b646c28c5adb1bc2bc2e1f3fc590d51f4fff91e720857e61e544af7413 days 19 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0x78f205631ff9ab3d3848655abc15c4567451330b0379cb97532ad5de87730cec13 days 20 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xa9700a5a93970123c7c5b5029aeffe7b0c50968f587c15c7cc13146f0c14ea2113 days 21 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007060241
0xc580e819bffce818fd71120ddaf3c06ab92e405bb7788dee852164eadbc1e87413 days 21 hrs ago0x2a3b59ac638f90d82bdaf5e2da5d37c1a31b29f3  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.007257041
0xbaba0c62ff9f0a86277367b9979a7fa358f0742c472a82cf10b8dfeb01cea2a3111 days 14 hrs ago0xe4e18a49c6f1210ffe9a60dbd38071c6ef78d982  IN   0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether0.00082236
0xa8813970462d0e581e3ad32134069e258d0db264969378223db2504ccd9ccc76111 days 14 hrs ago0xe4e18a49c6f1210ffe9a60dbd38071c6ef78d982  IN    Contract Creation0 Ether0.00619497
[ Download CSV Export  ] 
 Internal Transactions as a result of Contract Execution
 Latest 25 Internal Txns, Click here To View More View All
ParentTxHash Block Age From To Value
0xb177814898371c3ae756467bf47b07797ab9a994f90cccf9b0efd72aeb9d204738562138 days 12 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xb177814898371c3ae756467bf47b07797ab9a994f90cccf9b0efd72aeb9d204738562138 days 12 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether
0x5bfb6bbdf821108ff0c97fb730003c35ae6cf14a0eb2e12fe360f739616a8abe38562128 days 12 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0x5bfb6bbdf821108ff0c97fb730003c35ae6cf14a0eb2e12fe360f739616a8abe38562128 days 12 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x3ca6946ad30d6f3c983cd45f6c3677476f8625c228f962b5443a119588ffcd0e38551868 days 16 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x3ca6946ad30d6f3c983cd45f6c3677476f8625c228f962b5443a119588ffcd0e38551868 days 16 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether
0xd48f395a7603787013213d60787daeca832de95bd283a23386eba6b0e340f86738551858 days 16 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0xd48f395a7603787013213d60787daeca832de95bd283a23386eba6b0e340f86738551858 days 16 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xf61f5338157e2e603455ddb0c2af5496d92cb354010abef977df3b5f726376de38550788 days 17 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xf61f5338157e2e603455ddb0c2af5496d92cb354010abef977df3b5f726376de38550788 days 17 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether
0x3f51ef2cc02aed16a482e32de71335f76fba2b3a5d5f1f17fb19fc394898166438550778 days 17 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0x3f51ef2cc02aed16a482e32de71335f76fba2b3a5d5f1f17fb19fc394898166438550778 days 17 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xde001bb127ac467ef04b70d3ad742154969794dd9350345b985c80a52d1c45e0383744211 days 18 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xde001bb127ac467ef04b70d3ad742154969794dd9350345b985c80a52d1c45e0383744211 days 18 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether
0x60b98835441c944431aea216027dbf7ae62e53b6d5f9a3b62b9801dbb8d9820a383744111 days 18 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0x60b98835441c944431aea216027dbf7ae62e53b6d5f9a3b62b9801dbb8d9820a383744111 days 18 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xe56f8c3c61d70547deb3df4f2df0dbac7ba88fc4b1b1f17b5d72c6f92efb06d0383737211 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0xe56f8c3c61d70547deb3df4f2df0dbac7ba88fc4b1b1f17b5d72c6f92efb06d0383737211 days 19 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether
0x0ae21340a2d13bcec9b85137db3fee39e5661ada51fe20cf5926242d2421d6c2383737111 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0x0ae21340a2d13bcec9b85137db3fee39e5661ada51fe20cf5926242d2421d6c2383737111 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x96c0983a2e7d9948ca5768e1fed13f9c680759c84bdca012ce0646223828031b383725311 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x96c0983a2e7d9948ca5768e1fed13f9c680759c84bdca012ce0646223828031b383725311 days 19 hrs ago0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40xf7fbe8467dc230316e04bbe00c5c811a18886a7e0 Ether
0x8f8efad22f198f201085b11b94524551902ce269eb6028d13d2a8affd3dc3465383725211 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0x13a59ba5aaa130482ec11d9e4ba8bb688b1c38a40 Ether
0x8f8efad22f198f201085b11b94524551902ce269eb6028d13d2a8affd3dc3465383725211 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
0x69a68ea6fde6bca81193b47a0d265729cfcd637c1ef5a11ec6ae46060d5cb79a383720811 days 19 hrs ago0xf7fbe8467dc230316e04bbe00c5c811a18886a7e0xe987926a226932dfb1f71fa316461db272e053170 Ether
[ Download CSV Export  ] 
Contract Source Code Verified (Exact Match)
Contract Name: CoinbaseEthUsd
Compiler Version: v0.4.25+commit.59dbf8f1
Optimization Enabled: Yes
Runs (Optimiser):  200



  Contract Source Code   Find Similiar Contracts

pragma solidity ^0.4.24;

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
contract Ownable {
  address private _owner;

  event OwnershipRenounced(address indexed previousOwner);
  event OwnershipTransferred(
    address indexed previousOwner,
    address indexed newOwner
  );

  /**
   * @dev The Ownable constructor sets the original `owner` of the contract to the sender
   * account.
   */
  constructor() public {
    _owner = msg.sender;
  }

  /**
   * @return the address of the owner.
   */
  function owner() public view returns(address) {
    return _owner;
  }

  /**
   * @dev Throws if called by any account other than the owner.
   */
  modifier onlyOwner() {
    require(isOwner());
    _;
  }

  /**
   * @return true if `msg.sender` is the owner of the contract.
   */
  function isOwner() public view returns(bool) {
    return msg.sender == _owner;
  }

  /**
   * @dev Allows the current owner to relinquish control of the contract.
   * @notice Renouncing to ownership will leave the contract without an owner.
   * It will not be possible to call the functions with the `onlyOwner`
   * modifier anymore.
   */
  function renounceOwnership() public onlyOwner {
    emit OwnershipRenounced(_owner);
    _owner = address(0);
  }

  /**
   * @dev Allows the current owner to transfer control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function transferOwnership(address newOwner) public onlyOwner {
    _transferOwnership(newOwner);
  }

  /**
   * @dev Transfers control of the contract to a newOwner.
   * @param newOwner The address to transfer ownership to.
   */
  function _transferOwnership(address newOwner) internal {
    require(newOwner != address(0));
    emit OwnershipTransferred(_owner, newOwner);
    _owner = newOwner;
  }
}

// Util functions imported in OnChainSDK for caller to use.
library utils {
    uint constant UINT256MAX = ~uint(0);
    
    // A decimal byte to uint. Return value of 10 indicating invalid input.
    function byte2Uint(byte b) internal pure returns(uint) {
        if (b >= '0' && b <= '9') {
            return uint(b) - 48;  // '0'
        }
        // Indicating invalid input.
        return 10;
    }
    // Return value of 16 indicating invalid input.
    function hexByte2Uint(byte b) internal pure returns(uint) {
        if (b >= '0' && b <= '9') {
            return uint(b) - 48;  // '0'
        } else if (b >= 'A' && b <= 'F') {
            return uint(b) - 55;
        } else if (b >= 'a' && b <= 'f') {
            return uint(b) - 87;
        }
        // Indicating invalid input.
        return 16;
    }
    
    /// StringToXXX helpers.
    
    // A decimal string (charset c in [0-9]) to uint. Like atoi(),
    // 1. processing stops once encountering character not in charset c.
    // 2. returns UINT256MAX when overflow.
    function str2Uint(string a) internal pure returns(uint) {
        bytes memory b = bytes(a);
        uint res = 0;
        for (uint i = 0; i < b.length; i++) {
            uint tmp = byte2Uint(b[i]);
            if (tmp >= 10) {
                return res;
            } else {
                // Overflow.
                if (res >= UINT256MAX / 10) {
                    return UINT256MAX;
                }
                res = res * 10 + tmp;
            }
        }
        return res;
    }
    
    // Hex string (charset c in [0-9A-Za-z]) to uint. Like atoi(),
    // 1. processing stops once encountering character not in charset c.
    // 2. returns UINT256MAX when overflow.
    function hexStr2Uint(string a) internal pure returns(uint) {
        bytes memory b = bytes(a);
        uint res = 0;
        uint i = 0;
        if (b.length >= 2 && b[0] == '0' && (b[1] == 'x' || b[1] == 'X')) {
            i += 2;
        }
        for (; i < b.length; i++) {
            uint tmp = hexByte2Uint(b[i]);
            if (tmp >= 16) {
                return res;
            } else {
                // Overflow.
                if (res >= UINT256MAX / 16) {
                    return UINT256MAX;
                }
                res = res * 16 + tmp;
            }
        }
        return res;
    }
    
    // Input: 20-byte hex string without or with 0x/0X prefix (40 characters or 42 characters)
    // Example: '0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263' => address(0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263)
    // address is of uint160.
    function str2Addr(string a) internal pure returns(address) {
        bytes memory b = bytes(a);
        require(b.length == 40 || b.length == 42, "Invalid input, should be 20-byte hex string");
        uint i = 0;
        if (b.length == 42) {
            i += 2;
        }
        
        uint160 res = 0;
        for (; i < b.length; i += 2) {
            res *= 256;
            
            uint160 b1 = uint160(hexByte2Uint(b[i]));
            uint160 b2 = uint160(hexByte2Uint(b[i+1]));
            require(b1 < 16 && b2 < 16, "address string with invalid character");
            
            res += b1 * 16 + b2;
        }
        return address(res);
    }
    
    /// XXXToString() helpers.
    
    // Example: 12 -> 'c' (without 0x/0X prefix).
    function uint2HexStr(uint x) internal pure returns(string) {
        if (x == 0) return '0';
        
        uint j = x;
        uint len;
        while (j != 0) {
            len++;
            j /= 16;
        }
        
        bytes memory b = new bytes(len);
        uint k = len - 1;
        while (x != 0) {
            uint curr = (x & 0xf);
            b[k--] = curr > 9 ? byte(55 + curr) : byte(48 + curr);
            x /= 16;
        }
        return string(b);
    }
    
    // Example: 12 -> "12"
    function uint2Str(uint x) internal pure returns(string) {
        if (x == 0) return '0';
        
        uint j = x;
        uint len;
        while (j != 0) {
            len++;
            j /= 10;
        }
        
        bytes memory b = new bytes(len);
        uint k = len - 1;
        while (x != 0) {
            b[k--] = byte(48 + x % 10);
            x /= 10;
        }
        return string(b);
    }
    
    // Example: address(0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263) => '0e7ad63d2a305a7b9f46541c386aafbd2af6b263'
    function addr2Str(address x) internal pure returns(string) {
        bytes memory b = new bytes(20);
        for (uint i = 0; i < 20; i++) {
            b[i] = byte(uint8(uint(x) / (2**(8*(19 - i)))));
        }
        return string(b);
    }
    
    /// bytes/string helpers.
    
    function bytesConcat(bytes a, bytes b) internal pure returns(bytes) {
        bytes memory concated = new bytes(a.length + b.length);
        uint i = 0;
        uint k = 0;
        while (i < a.length) { concated[k++] = a[i++]; }
        i = 0;
        while(i < b.length) { concated[k++] = b[i++]; }
        return concated;
    }
    
    function strConcat(string a, string b) internal pure returns(string) {
        bytes memory aa = bytes(a);
        bytes memory bb = bytes(b);
        return string(bytesConcat(aa, bb));
    }
    
    function bytesCompare(bytes a, bytes b) internal pure returns(int) {
        uint len = a.length < b.length ? a.length : b.length;
        for (uint i = 0; i < len; i++) {
            if (a[i] < b[i]) {
                return -1;
            } else if (a[i] > b[i]) {
                return 1;
            }
        }
        if (a.length < b.length) {
            return -1;
        } else if (a.length > b.length) {
            return 1;
        } else {
            return 0;
        }
    }
    
    // "abd" > "abcde"
    function strCompare(string a, string b) internal pure returns(int) {
        bytes memory aa = bytes(a);
        bytes memory bb = bytes(b);
        return bytesCompare(aa, bb);
    }
    
    function bytesEqual(bytes a, bytes b) internal pure returns(bool) {
        return (a.length == b.length) && (bytesCompare(a, b) == 0);
    }
    
    function strEqual(string a, string b) internal pure returns(bool) {
        bytes memory aa = bytes(a);
        bytes memory bb = bytes(b);
        return bytesEqual(aa, bb);
    }

    // Return the index of needle's first occurrance in haystack. Return value
    // of -1 indicating no occurrance.
    // Useful in case of parsing float string "123.45".
    // Example:
    //   indexOf('123', '') => 0
    //   indexOf('', '45') => -1
    //   indexOf('123', '1234') => -1
    //   indexOf('123.45', '.') => 3
    function indexOf(string haystack, string needle) internal pure returns(int) {
        bytes memory b_haystack = bytes(haystack);
        bytes memory b_needle = bytes(needle);
        return indexOf(b_haystack, b_needle);
    }

    function indexOf(bytes haystack, bytes needle) internal pure returns(int) {
        if (needle.length == 0) {
            return 0;
        } else if (haystack.length < needle.length) {
            return -1;
        }
        // Instead of O(haystack.length x needle.length), saving gas using KMP:
        // O(haystack.length + needle.length)
        uint[] memory pi = new uint[](needle.length + 1);
        pi[1] = 0;
        uint k = 0;
        // KMP pre-processing
        for(uint q = 2; q <= needle.length; q++) {
            while(k > 0 && needle[k] != needle[q-1]) {
                k = pi[k];
            }
            if(needle[k] == needle[q-1]) {
                k++;
            }
            pi[q] = k;
        }
        // KMP matching
        q = 0;
        for(uint i = 0; i < haystack.length; i++) {
            while(q > 0 && needle[q] != haystack[i]) {
                q = pi[q];
            }
            if(needle[q] == haystack[i]) {
                q++;
            }
            // Match
            if(q == needle.length) {
                return int(i - q + 1);
            }
        }
        // No match
        return -1;
    }

    // subStr("1234567890", 2, 5) => "34567"
    // [start, start + len), index starting from 0.
    function subStr(bytes a, uint start, uint len) internal pure returns(bytes) {
       require(start < a.length && start + len > start && start + len <= a.length,
               "Invalid start index or length out of range");
       bytes memory res = new bytes(len);
       for (uint i = 0; i < len; i++) {
           res[i] = a[start + i];
       }
       return res;
    }

    // string num = "123.4567";
    // subStr(num, indexOf(num, '.') + 1) => "4567"
    function subStr(bytes a, uint start) internal pure returns(bytes) {
        require(start < a.length, "Invalid start index out of range");
        return subStr(a, start, a.length - start);
    }

    function subStr(string a, uint start, uint len) internal pure returns(string) {
        bytes memory aa = bytes(a);
        return string(subStr(aa, start, len));
    }

    function subStr(string a, uint start) internal pure returns(string) {
        bytes memory aa = bytes(a);
        return string(subStr(aa, start));
    }
}

interface DOSProxyInterface {
    function query(address, uint, string, string) external returns (uint);
    function requestRandom(address, uint8, uint) external returns (uint);
}

interface DOSAddressBridgeInterface {
    function getProxyAddress() external view returns (address);
}

contract DOSOnChainSDK {
    using utils for *;

    DOSProxyInterface dosProxy;
    DOSAddressBridgeInterface dosAddrBridge =
        DOSAddressBridgeInterface(0xe987926A226932DFB1f71FA316461db272E05317);

    modifier resolveAddress {
        dosProxy = DOSProxyInterface(dosAddrBridge.getProxyAddress());
        _;
    }

    function fromDOSProxyContract() internal view returns (address) {
        return dosAddrBridge.getProxyAddress();
    }

    // @dev: Call this function to get a unique queryId to differentiate
    //       parallel requests. A return value of 0x0 stands for error and a
    //       related event would be emitted.
    // @timeout: Estimated timeout in seconds specified by caller; e.g. 15.
    //           Response is not guaranteed if processing time exceeds this.
    // @dataSource: Data source destination specified by caller.
    //              E.g.: 'https://api.coinbase.com/v2/prices/ETH-USD/spot'
    // @selector: A selector expression provided by caller to filter out
    //            specific data fields out of the raw response. The response
    //            data format (json, xml/html, and more) is identified from
    //            the selector expression.
    //            E.g. Use "$.data.amount" to extract "194.22" out.
    //             {
    //                  "data":{
    //                          "base":"ETH",
    //                          "currency":"USD",
    //                          "amount":"194.22"
    //                  }
    //             }
    //            Check below documentation for details.
    //            (https://dosnetwork.github.io/docs/#/contents/blockchains/ethereum?id=selector).
    function DOSQuery(uint timeout, string dataSource, string selector)
        resolveAddress
        internal
        returns (uint)
    {
        return dosProxy.query(this, timeout, dataSource, selector);
    }

    // @dev: Must override __callback__ to process a corresponding response. A
    //       user-defined event could be added to notify the Dapp frontend that
    //       the response is ready.
    // @queryId: A unique queryId returned by DOSQuery() for callers to
    //           differentiate parallel responses.
    // @result: Response for the specified queryId.
    function __callback__(uint queryId, bytes result) external {
        // To be overridden in the caller contract.
    }

    // @dev: Call this function to request either a fast but insecure random
    //       number or a safe and secure random number delivered back
    //       asynchronously through the __callback__ function.
    //       Depending on the mode, the return value would be a random number
    //       (for fast mode) or a requestId (for safe mode).
    // @mode: 1: safe mode - The asynchronous but safe way to generate a new
    //                       secure random number by a group of off-chain
    //                       clients using VRF and Threshold Signature. There
    //                       would be a fee to run in safe mode.
    //        0: fast mode - Return a random number in one invocation directly.
    //                       The returned random is the sha3 hash of latest
    //                       generated random number by DOS Network combining
    //                       with the optional seed.
    //                       Thus the result should NOT be considered safe and
    //                       is for testing purpose only. It's free of charge.
    // @seed: Optional random seed provided by caller.
    function DOSRandom(uint8 mode, uint seed)
        resolveAddress
        internal
        returns (uint)
    {
        return dosProxy.requestRandom(this, mode, seed);
    }

    // @dev: Must override __callback__ to process a corresponding random
    //       number. A user-defined event could be added to notify the Dapp
    //       frontend that a new secure random number is generated.
    // @requestId: A unique requestId returned by DOSRandom() for requester to
    //             differentiate random numbers generated concurrently.
    // @generatedRandom: Generated secure random number for the specific
    //                   requestId.
    function __callback__(uint requestId, uint generatedRandom) external {
        // To be overridden in the caller contract.
    }
}

// An example get latest ETH-USD price from Coinbase
contract CoinbaseEthUsd is Ownable, DOSOnChainSDK {
    // Struct to hold parsed floating string "123.45"
    struct ethusd {
        uint integral;
        uint fractional;
    }
    uint queryId;
    string public price_str;
    ethusd public prices;
    
    event GetPrice(uint integral, uint fractional);
    
    function check() public {
        queryId = DOSQuery(30, "https://api.coinbase.com/v2/prices/ETH-USD/spot", "$.data.amount");
    }
    
    modifier auth {
        // Filter out malicious __callback__ callers.
        require(msg.sender == fromDOSProxyContract(), "Unauthenticated response");
        _;
    }
    
    function __callback__(uint id, bytes result) external auth {
        require(queryId == id, "Unmatched response");
        
        price_str = string(result);
        prices.integral = price_str.subStr(1).str2Uint();
        int delimit_idx = price_str.indexOf('.');
        if (delimit_idx != -1) {
            prices.fractional = price_str.subStr(uint(delimit_idx + 1)).str2Uint();
        }
        emit GetPrice(prices.integral, prices.fractional);
    }
}

    Contract ABI  
[{"constant":false,"inputs":[{"name":"requestId","type":"uint256"},{"name":"generatedRandom","type":"uint256"}],"name":"__callback__","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"id","type":"uint256"},{"name":"result","type":"bytes"}],"name":"__callback__","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"isOwner","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"check","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"prices","outputs":[{"name":"integral","type":"uint256"},{"name":"fractional","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"price_str","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"integral","type":"uint256"},{"indexed":false,"name":"fractional","type":"uint256"}],"name":"GetPrice","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"}],"name":"OwnershipRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]

  Contract Creation Code Switch To Opcodes View
608060405260028054600160a060020a031990811673e987926a226932dfb1f71fa316461db272e05317179091556000805490911633179055611109806100476000396000f3006080604052600436106100985763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166318a1908d811461009d5780636d112977146100ba578063715018a6146100de5780638da5cb5b146100f35780638f32d59b14610124578063919840ad1461014d578063d3419bf314610162578063ebec22cb14610190578063f2fde38b1461021a575b600080fd5b3480156100a957600080fd5b506100b860043560243561023b565b005b3480156100c657600080fd5b506100b860048035906024803590810191013561023f565b3480156100ea57600080fd5b506100b8610540565b3480156100ff57600080fd5b506101086105a8565b60408051600160a060020a039092168252519081900360200190f35b34801561013057600080fd5b506101396105b8565b604080519115158252519081900360200190f35b34801561015957600080fd5b506100b86105c9565b34801561016e57600080fd5b5061017761066b565b6040805192835260208301919091528051918290030190f35b34801561019c57600080fd5b506101a5610674565b6040805160208082528351818301528351919283929083019185019080838360005b838110156101df5781810151838201526020016101c7565b50505050905090810190601f16801561020c5780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561022657600080fd5b506100b8600160a060020a0360043516610702565b5050565b6000610249610721565b600160a060020a031633146102a8576040805160e560020a62461bcd02815260206004820152601860248201527f556e61757468656e7469636174656420726573706f6e73650000000000000000604482015290519081900360640190fd5b6003548414610301576040805160e560020a62461bcd02815260206004820152601260248201527f556e6d61746368656420726573706f6e73650000000000000000000000000000604482015290519081900360640190fd5b61030d60048484611045565b50600480546040805160206002600180861615610100026000190190951604601f81018290048202830182019093528282526103b3946103ae9493909183018282801561039b5780601f106103705761010080835404028352916020019161039b565b820191906000526020600020905b81548152906001019060200180831161037e57829003601f168201915b50505050506107b190919063ffffffff16565b6107c6565b60055560408051808201825260018082527f2e00000000000000000000000000000000000000000000000000000000000000602080840191909152600480548551600294821615610100026000190190911693909304601f81018390048302840183019095528483526104869490918301828280156104735780601f1061044857610100808354040283529160200191610473565b820191906000526020600020905b81548152906001019060200180831161045657829003601f168201915b505050505061086290919063ffffffff16565b905060001981146104f957600480546040805160206002600180861615610100026000190190951604601f81018290048202830182019093528282526104f5946103ae94870193909183018282801561039b5780601f106103705761010080835404028352916020019161039b565b6006555b60055460065460408051928352602083019190915280517f3bb187a633483f48a5c6c78b61fc0a0b41da340ba695f2b74683e5fa7d33855f9281900390910190a150505050565b6105486105b8565b151561055357600080fd5b60008054604051600160a060020a03909116917ff8df31144d9c2f0f6b59d69b8b98abd5459d07f2742c4df920b25aae33c6482091a26000805473ffffffffffffffffffffffffffffffffffffffff19169055565b600054600160a060020a03165b90565b600054600160a060020a0316331490565b610666601e606060405190810160405280602f81526020017f68747470733a2f2f6170692e636f696e626173652e636f6d2f76322f7072696381526020017f65732f4554482d5553442f73706f7400000000000000000000000000000000008152506040805190810160405280600d81526020017f242e646174612e616d6f756e7400000000000000000000000000000000000000815250610879565b600355565b60055460065482565b6004805460408051602060026001851615610100026000190190941693909304601f810184900484028201840190925281815292918301828280156106fa5780601f106106cf576101008083540402835291602001916106fa565b820191906000526020600020905b8154815290600101906020018083116106dd57829003601f168201915b505050505081565b61070a6105b8565b151561071557600080fd5b61071e81610a9d565b50565b600254604080517f43a73d9a0000000000000000000000000000000000000000000000000000000081529051600092600160a060020a0316916343a73d9a91600480830192602092919082900301818787803b15801561078057600080fd5b505af1158015610794573d6000803e3d6000fd5b505050506040513d60208110156107aa57600080fd5b5051905090565b6060826107be8184610b1a565b949350505050565b6000818180805b8351821015610855576107ff84838151811015156107e757fe5b90602001015160f860020a900460f860020a02610b8a565b9050600a811061081157829450610859565b7f19999999999999999999999999999999999999999999999999999999999999998310610842576000199450610859565b8083600a020192506001909101906107cd565b8294505b50505050919050565b600082826108708282610c3f565b95945050505050565b600254604080517f43a73d9a0000000000000000000000000000000000000000000000000000000081529051600092600160a060020a0316916343a73d9a91600480830192602092919082900301818787803b1580156108d857600080fd5b505af11580156108ec573d6000803e3d6000fd5b505050506040513d602081101561090257600080fd5b50516001805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392831617908190556040517fb7fb8fd7000000000000000000000000000000000000000000000000000000008152306004820181815260248301899052608060448401908152885160848501528851949095169463b7fb8fd79492938a938a938a9390929091606482019160a40190602087019080838360005b838110156109b95781810151838201526020016109a1565b50505050905090810190601f1680156109e65780820380516001836020036101000a031916815260200191505b50838103825284518152845160209182019186019080838360005b83811015610a19578181015183820152602001610a01565b50505050905090810190601f168015610a465780820380516001836020036101000a031916815260200191505b509650505050505050602060405180830381600087803b158015610a6957600080fd5b505af1158015610a7d573d6000803e3d6000fd5b505050506040513d6020811015610a9357600080fd5b5051949350505050565b600160a060020a0381161515610ab257600080fd5b60008054604051600160a060020a03808516939216917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e091a36000805473ffffffffffffffffffffffffffffffffffffffff1916600160a060020a0392909216919091179055565b81516060908210610b75576040805160e560020a62461bcd02815260206004820181905260248201527f496e76616c696420737461727420696e646578206f7574206f662072616e6765604482015290519081900360640190fd5b610b83838384865103610f0c565b9392505050565b60007f30000000000000000000000000000000000000000000000000000000000000007fff00000000000000000000000000000000000000000000000000000000000000831610801590610c2057507f39000000000000000000000000000000000000000000000000000000000000007fff00000000000000000000000000000000000000000000000000000000000000831611155b15610c365750602f1960f860020a820401610c3a565b50600a5b919050565b600060606000806000855160001415610c5b5760009450610f02565b855187511015610c6f576000199450610f02565b8551600101604051908082528060200260200182016040528015610c9d578160200160208202803883390190505b5093506000846001815181101515610cb157fe5b6020908102909101015260009250600291505b85518211610de2575b600083118015610d3457508560018303815181101515610ce957fe5b90602001015160f860020a900460f860020a02600160f860020a0319168684815181101515610d1457fe5b90602001015160f860020a900460f860020a02600160f860020a03191614155b15610d58578383815181101515610d4757fe5b906020019060200201519250610ccd565b8560018303815181101515610d6957fe5b90602001015160f860020a900460f860020a02600160f860020a0319168684815181101515610d9457fe5b90602001015160f860020a900460f860020a02600160f860020a0319161415610dbe576001909201915b828483815181101515610dcd57fe5b60209081029091010152600190910190610cc4565b5060009050805b8651811015610efc575b600082118015610e5757508681815181101515610e0c57fe5b90602001015160f860020a900460f860020a02600160f860020a0319168683815181101515610e3757fe5b90602001015160f860020a900460f860020a02600160f860020a03191614155b15610e7b578382815181101515610e6a57fe5b906020019060200201519150610df3565b8681815181101515610e8957fe5b90602001015160f860020a900460f860020a02600160f860020a0319168683815181101515610eb457fe5b90602001015160f860020a900460f860020a02600160f860020a0319161415610ede576001909101905b8551821415610ef4578181036001019450610f02565b600101610de9565b60001994505b5050505092915050565b6060806000855185108015610f22575084848601115b8015610f315750855184860111155b1515610fad576040805160e560020a62461bcd02815260206004820152602a60248201527f496e76616c696420737461727420696e646578206f72206c656e677468206f7560448201527f74206f662072616e676500000000000000000000000000000000000000000000606482015290519081900360840190fd5b836040519080825280601f01601f191660200182016040528015610fdb578160200160208202803883390190505b509150600090505b8381101561103c5785818601815181101515610ffb57fe5b90602001015160f860020a900460f860020a02828281518110151561101c57fe5b906020010190600160f860020a031916908160001a905350600101610fe3565b50949350505050565b828054600181600116156101000203166002900490600052602060002090601f016020900481019282601f106110865782800160ff198235161785556110b3565b828001600101855582156110b3579182015b828111156110b3578235825591602001919060010190611098565b506110bf9291506110c3565b5090565b6105b591905b808211156110bf57600081556001016110c95600a165627a7a72305820bc041f84120ab0f927107d69d8572c8141fa1c3541470fb669d00c7531d224b20029

   Swarm Source:
bzzr://bc041f84120ab0f927107d69d8572c8141fa1c3541470fb669d00c7531d224b2

 

View All
Block Age transaction Difficulty GasUsed Reward
View All
Block Age UncleNumber Difficulty GasUsed Reward