├── ATestnetConsumerTaiko.sol ├── LinkToken.sol ├── Operator.sol ├── README.md ├── testRequestBool.sol ├── testRequestBytes.sol ├── testRequestBytes32.sol ├── testRequestInt256.sol ├── testRequestString.sol └── testRequestUint256.sol /ATestnetConsumerTaiko.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract ATestnetConsumerTaiko is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "dd42445e651744348535405fb08f3cff"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | uint256 public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | uint256 indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://min-api.cryptocompare.com/data/price?fsym=ETH&tsyms=USD" 33 | ); 34 | req.add("path", "USD"); 35 | req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | uint256 _price 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | emit RequestEthereumPriceFulfilled(_requestId, _price); 44 | currentPrice = _price; 45 | } 46 | 47 | function stringToBytes32( 48 | string memory source 49 | ) private pure returns (bytes32 result) { 50 | bytes memory tempEmptyStringTest = bytes(source); 51 | if (tempEmptyStringTest.length == 0) { 52 | return 0x0; 53 | } 54 | 55 | assembly { 56 | // solhint-disable-line no-inline-assembly 57 | result := mload(add(source, 32)) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /LinkToken.sol: -------------------------------------------------------------------------------- 1 | /** 2 | *Submitted for verification at Etherscan.io on 2017-09-23 3 | */ 4 | 5 | pragma solidity ^0.4.16; 6 | 7 | 8 | /** 9 | * @title SafeMath 10 | * @dev Math operations with safety checks that throw on error 11 | */ 12 | library SafeMath { 13 | function mul(uint256 a, uint256 b) internal constant returns (uint256) { 14 | uint256 c = a * b; 15 | assert(a == 0 || c / a == b); 16 | return c; 17 | } 18 | 19 | function div(uint256 a, uint256 b) internal constant returns (uint256) { 20 | // assert(b > 0); // Solidity automatically throws when dividing by 0 21 | uint256 c = a / b; 22 | // assert(a == b * c + a % b); // There is no case in which this doesn't hold 23 | return c; 24 | } 25 | 26 | function sub(uint256 a, uint256 b) internal constant returns (uint256) { 27 | assert(b <= a); 28 | return a - b; 29 | } 30 | 31 | function add(uint256 a, uint256 b) internal constant returns (uint256) { 32 | uint256 c = a + b; 33 | assert(c >= a); 34 | return c; 35 | } 36 | } 37 | 38 | 39 | /** 40 | * @title ERC20Basic 41 | * @dev Simpler version of ERC20 interface 42 | * @dev see https://github.com/ethereum/EIPs/issues/179 43 | */ 44 | contract ERC20Basic { 45 | uint256 public totalSupply; 46 | function balanceOf(address who) constant returns (uint256); 47 | function transfer(address to, uint256 value) returns (bool); 48 | event Transfer(address indexed from, address indexed to, uint256 value); 49 | } 50 | /** 51 | * @title ERC20 interface 52 | * @dev see https://github.com/ethereum/EIPs/issues/20 53 | */ 54 | contract ERC20 is ERC20Basic { 55 | function allowance(address owner, address spender) constant returns (uint256); 56 | function transferFrom(address from, address to, uint256 value) returns (bool); 57 | function approve(address spender, uint256 value) returns (bool); 58 | event Approval(address indexed owner, address indexed spender, uint256 value); 59 | } 60 | 61 | contract ERC677 is ERC20 { 62 | function transferAndCall(address to, uint value, bytes data) returns (bool success); 63 | 64 | event Transfer(address indexed from, address indexed to, uint value, bytes data); 65 | } 66 | 67 | contract ERC677Receiver { 68 | function onTokenTransfer(address _sender, uint _value, bytes _data); 69 | } 70 | 71 | /** 72 | * @title Basic token 73 | * @dev Basic version of StandardToken, with no allowances. 74 | */ 75 | contract BasicToken is ERC20Basic { 76 | using SafeMath for uint256; 77 | 78 | mapping(address => uint256) balances; 79 | 80 | /** 81 | * @dev transfer token for a specified address 82 | * @param _to The address to transfer to. 83 | * @param _value The amount to be transferred. 84 | */ 85 | function transfer(address _to, uint256 _value) returns (bool) { 86 | balances[msg.sender] = balances[msg.sender].sub(_value); 87 | balances[_to] = balances[_to].add(_value); 88 | Transfer(msg.sender, _to, _value); 89 | return true; 90 | } 91 | 92 | /** 93 | * @dev Gets the balance of the specified address. 94 | * @param _owner The address to query the the balance of. 95 | * @return An uint256 representing the amount owned by the passed address. 96 | */ 97 | function balanceOf(address _owner) constant returns (uint256 balance) { 98 | return balances[_owner]; 99 | } 100 | 101 | } 102 | 103 | 104 | /** 105 | * @title Standard ERC20 token 106 | * 107 | * @dev Implementation of the basic standard token. 108 | * @dev https://github.com/ethereum/EIPs/issues/20 109 | * @dev Based on code by FirstBlood: https://github.com/Firstbloodio/token/blob/master/smart_contract/FirstBloodToken.sol 110 | */ 111 | contract StandardToken is ERC20, BasicToken { 112 | 113 | mapping (address => mapping (address => uint256)) allowed; 114 | 115 | 116 | /** 117 | * @dev Transfer tokens from one address to another 118 | * @param _from address The address which you want to send tokens from 119 | * @param _to address The address which you want to transfer to 120 | * @param _value uint256 the amount of tokens to be transferred 121 | */ 122 | function transferFrom(address _from, address _to, uint256 _value) returns (bool) { 123 | var _allowance = allowed[_from][msg.sender]; 124 | 125 | // Check is not needed because sub(_allowance, _value) will already throw if this condition is not met 126 | // require (_value <= _allowance); 127 | 128 | balances[_from] = balances[_from].sub(_value); 129 | balances[_to] = balances[_to].add(_value); 130 | allowed[_from][msg.sender] = _allowance.sub(_value); 131 | Transfer(_from, _to, _value); 132 | return true; 133 | } 134 | 135 | /** 136 | * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. 137 | * @param _spender The address which will spend the funds. 138 | * @param _value The amount of tokens to be spent. 139 | */ 140 | function approve(address _spender, uint256 _value) returns (bool) { 141 | allowed[msg.sender][_spender] = _value; 142 | Approval(msg.sender, _spender, _value); 143 | return true; 144 | } 145 | 146 | /** 147 | * @dev Function to check the amount of tokens that an owner allowed to a spender. 148 | * @param _owner address The address which owns the funds. 149 | * @param _spender address The address which will spend the funds. 150 | * @return A uint256 specifying the amount of tokens still available for the spender. 151 | */ 152 | function allowance(address _owner, address _spender) constant returns (uint256 remaining) { 153 | return allowed[_owner][_spender]; 154 | } 155 | 156 | /* 157 | * approve should be called when allowed[_spender] == 0. To increment 158 | * allowed value is better to use this function to avoid 2 calls (and wait until 159 | * the first transaction is mined) 160 | * From MonolithDAO Token.sol 161 | */ 162 | function increaseApproval (address _spender, uint _addedValue) 163 | returns (bool success) { 164 | allowed[msg.sender][_spender] = allowed[msg.sender][_spender].add(_addedValue); 165 | Approval(msg.sender, _spender, allowed[msg.sender][_spender]); 166 | return true; 167 | } 168 | 169 | function decreaseApproval (address _spender, uint _subtractedValue) 170 | returns (bool success) { 171 | uint oldValue = allowed[msg.sender][_spender]; 172 | if (_subtractedValue > oldValue) { 173 | allowed[msg.sender][_spender] = 0; 174 | } else { 175 | allowed[msg.sender][_spender] = oldValue.sub(_subtractedValue); 176 | } 177 | Approval(msg.sender, _spender, allowed[msg.sender][_spender]); 178 | return true; 179 | } 180 | 181 | } 182 | 183 | contract ERC677Token is ERC677 { 184 | 185 | /** 186 | * @dev transfer token to a contract address with additional data if the recipient is a contact. 187 | * @param _to The address to transfer to. 188 | * @param _value The amount to be transferred. 189 | * @param _data The extra data to be passed to the receiving contract. 190 | */ 191 | function transferAndCall(address _to, uint _value, bytes _data) 192 | public 193 | returns (bool success) 194 | { 195 | super.transfer(_to, _value); 196 | Transfer(msg.sender, _to, _value, _data); 197 | if (isContract(_to)) { 198 | contractFallback(_to, _value, _data); 199 | } 200 | return true; 201 | } 202 | 203 | 204 | // PRIVATE 205 | 206 | function contractFallback(address _to, uint _value, bytes _data) 207 | private 208 | { 209 | ERC677Receiver receiver = ERC677Receiver(_to); 210 | receiver.onTokenTransfer(msg.sender, _value, _data); 211 | } 212 | 213 | function isContract(address _addr) 214 | private 215 | returns (bool hasCode) 216 | { 217 | uint length; 218 | assembly { length := extcodesize(_addr) } 219 | return length > 0; 220 | } 221 | 222 | } 223 | 224 | contract LinkToken is StandardToken, ERC677Token { 225 | 226 | uint public constant totalSupply = 10**27; 227 | string public constant name = 'ChainLink Token'; 228 | uint8 public constant decimals = 18; 229 | string public constant symbol = 'LINK'; 230 | 231 | function LinkToken() 232 | public 233 | { 234 | balances[msg.sender] = totalSupply; 235 | } 236 | 237 | /** 238 | * @dev transfer token to a specified address with additional data if the recipient is a contract. 239 | * @param _to The address to transfer to. 240 | * @param _value The amount to be transferred. 241 | * @param _data The extra data to be passed to the receiving contract. 242 | */ 243 | function transferAndCall(address _to, uint _value, bytes _data) 244 | public 245 | validRecipient(_to) 246 | returns (bool success) 247 | { 248 | return super.transferAndCall(_to, _value, _data); 249 | } 250 | 251 | /** 252 | * @dev transfer token to a specified address. 253 | * @param _to The address to transfer to. 254 | * @param _value The amount to be transferred. 255 | */ 256 | function transfer(address _to, uint _value) 257 | public 258 | validRecipient(_to) 259 | returns (bool success) 260 | { 261 | return super.transfer(_to, _value); 262 | } 263 | 264 | /** 265 | * @dev Approve the passed address to spend the specified amount of tokens on behalf of msg.sender. 266 | * @param _spender The address which will spend the funds. 267 | * @param _value The amount of tokens to be spent. 268 | */ 269 | function approve(address _spender, uint256 _value) 270 | public 271 | validRecipient(_spender) 272 | returns (bool) 273 | { 274 | return super.approve(_spender, _value); 275 | } 276 | 277 | /** 278 | * @dev Transfer tokens from one address to another 279 | * @param _from address The address which you want to send tokens from 280 | * @param _to address The address which you want to transfer to 281 | * @param _value uint256 the amount of tokens to be transferred 282 | */ 283 | function transferFrom(address _from, address _to, uint256 _value) 284 | public 285 | validRecipient(_to) 286 | returns (bool) 287 | { 288 | return super.transferFrom(_from, _to, _value); 289 | } 290 | 291 | 292 | // MODIFIERS 293 | 294 | modifier validRecipient(address _recipient) { 295 | require(_recipient != address(0) && _recipient != address(this)); 296 | _; 297 | } 298 | 299 | } 300 | -------------------------------------------------------------------------------- /Operator.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.7.6; 3 | import "@chainlink/contracts/src/v0.7/Operator.sol"; 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # chainlink-contract-testing 2 | 3 | 1. Deployed LinkToken.sol (ERC-677 standard https://github.com/ethereum/EIPs/issues/677): 4 | 5 | https://explorer.test.taiko.xyz/token/0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11/token-transfers 6 | 7 | 2. Deployed Operator.sol: 8 | 9 | https://explorer.test.taiko.xyz/address/0x7053af6475b2a11Bff65E697E349d66e6580d371 10 | 11 | 3. Added Chainlink node address to oracle list with a jobId specification setup with TOML file (see chainlink-taiko): 12 | 13 | ⚠️ Chainlnk node address 0x6FC84537f182329edCB488480837BDf210AF440d is a local node (will need to migrate to a hosted node on AWS or Linode) ⚠️ 14 | 15 | ```solidity 16 | setAuthorizedSenders["0x6FC84537f182329edCB488480837BDf210AF440d"] 17 | ``` 18 | 19 | 4. Deployed ATestnetConsumerTaiko.sol 20 | 21 | ⚠️ jobId depends on the node and job type and is subject to change if a local node is reset like its address ⚠️ 22 | 23 | https://explorer.test.taiko.xyz/address/0x576E0bEf1a772B6da1B0a6BA50E2426E5eB38465 24 | 25 | 5. Sent 1.00 LINK to ATestnetConsumerTaiko.sol 26 | 27 | https://explorer.test.taiko.xyz/tx/0x85ec9de9111557c9760489a4153dc436f64b797dc80411e62df273dc40cc6c78 28 | 29 | 6. Request ETH/USD: 30 | 31 | ⚠️ Make sure the Chainlink node has 1.0 ETH to update uint256 value and contract has 1.0 LINK to pay the Chainlink node ⚠️ 32 | 33 | https://explorer.test.taiko.xyz/tx/0xb1d0d9608b354acfbf6ec470203b042be52d786bb0dc275c3b9fa9efb88a6276 34 | 35 | Chainlink node automatic async response to update contract uint256 value: 36 | 37 | https://explorer.test.taiko.xyz/tx/0x00400a50f1eb8ab1fd949a2546e343ec0f9e497c4eabc459e84591ba783e8a03 38 | 39 | 7. Transaction for requesting ETH/USD did not revert, but will return 0 if Chainlink node is not setup to fulfill async request 40 | ``` 41 | currentPrice 42 | ``` 43 | returns 44 | ``` 45 | uint256: 173376 46 | ``` 47 | -------------------------------------------------------------------------------- /testRequestBool.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract testRequestBool is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "cc92cc23dd7742d58f018e6fef32da52"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | bool public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | bool indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://marcuswentz.github.io/chainlink_test_json_url_types/" 33 | ); 34 | req.add("path", "bool"); 35 | //req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | bool _id 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | emit RequestEthereumPriceFulfilled(_requestId, _id); 44 | currentPrice = _id; 45 | } 46 | 47 | function stringToBytes32( 48 | string memory source 49 | ) private pure returns (bytes32 result) { 50 | bytes memory tempEmptyStringTest = bytes(source); 51 | if (tempEmptyStringTest.length == 0) { 52 | return 0x0; 53 | } 54 | 55 | assembly { 56 | // solhint-disable-line no-inline-assembly 57 | result := mload(add(source, 32)) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /testRequestBytes.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract testRequestBytes is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "e0f10647ce9d47bb8b7e0d3f9ac97b60"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | bytes public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | bytes indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://marcuswentz.github.io/chainlink_test_json_url_types/" 33 | ); 34 | req.add("path", "bytes"); 35 | //req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | bytes calldata _id 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | emit RequestEthereumPriceFulfilled(_requestId, _id); 44 | currentPrice = _id; 45 | } 46 | 47 | function stringToBytes32( 48 | string memory source 49 | ) private pure returns (bytes32 result) { 50 | bytes memory tempEmptyStringTest = bytes(source); 51 | if (tempEmptyStringTest.length == 0) { 52 | return 0x0; 53 | } 54 | 55 | assembly { 56 | // solhint-disable-line no-inline-assembly 57 | result := mload(add(source, 32)) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /testRequestBytes32.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract testRequestBytes32 is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "e0f10647ce9d47bb8b7e0d3f9ac97b60"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | bytes32 public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | bytes32 indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://marcuswentz.github.io/chainlink_test_json_url_types/" 33 | ); 34 | req.add("path", "bytes32"); 35 | //req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | bytes calldata _id 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | bytes32 bytes32Id = bytes32(_id); 44 | emit RequestEthereumPriceFulfilled(_requestId, bytes32Id); 45 | currentPrice = bytes32Id; 46 | } 47 | 48 | function stringToBytes32( 49 | string memory source 50 | ) private pure returns (bytes32 result) { 51 | bytes memory tempEmptyStringTest = bytes(source); 52 | if (tempEmptyStringTest.length == 0) { 53 | return 0x0; 54 | } 55 | 56 | assembly { 57 | // solhint-disable-line no-inline-assembly 58 | result := mload(add(source, 32)) 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /testRequestInt256.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract testRequestInt256 is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "d6919224e60540b6a9570599ee3a4365"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | int256 public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | int256 indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://marcuswentz.github.io/chainlink_test_json_url_types/" 33 | ); 34 | req.add("path", "int256"); 35 | req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | int256 _price 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | emit RequestEthereumPriceFulfilled(_requestId, _price); 44 | currentPrice = _price; 45 | } 46 | 47 | function stringToBytes32( 48 | string memory source 49 | ) private pure returns (bytes32 result) { 50 | bytes memory tempEmptyStringTest = bytes(source); 51 | if (tempEmptyStringTest.length == 0) { 52 | return 0x0; 53 | } 54 | 55 | assembly { 56 | // solhint-disable-line no-inline-assembly 57 | result := mload(add(source, 32)) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /testRequestString.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract testRequestString is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "4a99df35ebe749aab98645ef6f03bf8f"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | string public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | string indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://marcuswentz.github.io/chainlink_test_json_url_types/" 33 | ); 34 | req.add("path", "string"); 35 | //req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | string calldata _id 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | emit RequestEthereumPriceFulfilled(_requestId, _id); 44 | currentPrice = _id; 45 | } 46 | 47 | function stringToBytes32( 48 | string memory source 49 | ) private pure returns (bytes32 result) { 50 | bytes memory tempEmptyStringTest = bytes(source); 51 | if (tempEmptyStringTest.length == 0) { 52 | return 0x0; 53 | } 54 | 55 | assembly { 56 | // solhint-disable-line no-inline-assembly 57 | result := mload(add(source, 32)) 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /testRequestUint256.sol: -------------------------------------------------------------------------------- 1 | // SPDX-License-Identifier: MIT 2 | pragma solidity 0.8.18; 3 | 4 | import "@chainlink/contracts/src/v0.8/ChainlinkClient.sol"; 5 | 6 | contract testRequestUint256 is ChainlinkClient { 7 | 8 | using Chainlink for Chainlink.Request; 9 | 10 | address constant oracleTaiko = 0x7053af6475b2a11Bff65E697E349d66e6580d371; 11 | string constant jobIdTaiko = "dd42445e651744348535405fb08f3cff"; 12 | uint256 public constant ORACLE_PAYMENT = (1 * LINK_DIVISIBILITY) / 10; // 0.1 * 10**18 (0.1 LINK) 13 | uint256 public currentPrice; 14 | 15 | event RequestEthereumPriceFulfilled( 16 | bytes32 indexed requestId, 17 | uint256 indexed price 18 | ); 19 | 20 | constructor() { 21 | setChainlinkToken(0xeC9a237864f7e78fd835Db717DB4e3d3c4254b11); 22 | } 23 | 24 | function requestEthereumPrice() public { 25 | Chainlink.Request memory req = buildChainlinkRequest( 26 | stringToBytes32(jobIdTaiko), 27 | address(this), 28 | this.fulfillEthereumPrice.selector 29 | ); 30 | req.add( 31 | "get", 32 | "https://marcuswentz.github.io/chainlink_test_json_url_types/" 33 | ); 34 | req.add("path", "uint256"); 35 | req.addInt("times", 100); 36 | sendChainlinkRequestTo(oracleTaiko, req, ORACLE_PAYMENT); 37 | } 38 | 39 | function fulfillEthereumPrice( 40 | bytes32 _requestId, 41 | uint256 _price 42 | ) public recordChainlinkFulfillment(_requestId) { 43 | emit RequestEthereumPriceFulfilled(_requestId, _price); 44 | currentPrice = _price; 45 | } 46 | 47 | function stringToBytes32( 48 | string memory source 49 | ) private pure returns (bytes32 result) { 50 | bytes memory tempEmptyStringTest = bytes(source); 51 | if (tempEmptyStringTest.length == 0) { 52 | return 0x0; 53 | } 54 | 55 | assembly { 56 | // solhint-disable-line no-inline-assembly 57 | result := mload(add(source, 32)) 58 | } 59 | } 60 | } 61 | --------------------------------------------------------------------------------