0

I'm trying to make a get request using the chainlink node. I'm following this tutorial this tutorial but the problem is that this is sending a request to this specific URL https://min-api.cryptocompare.com/data/pricemultifull?fsyms=ETH&tsyms=USD.

I, on the other hand, want to send a request that will change according to what happens inside the smart contract, for example, call https://myapi.com/?foo=0 or https://myapi.com/?foo=1 depending on specific conditions.

My solution so far has been to create a _buildRequestURI function that looks something like this:

function _buildRequestURI(Foo memory foo) public pure returns (string memory) {
    return string(abi.encodePacked(
      BASE_URI,
      "foo=", foo.foo
    ));
  }

Where Foo is my struct and foo.foo is an enum but for some reason foo.foo is not showing up on my final string. What am I doing wrong? Is there a better way to build this URL? Or better yet, add arguments to my get request? I'm using solidity 0.8.7

1 Answer 1

2

The current solution I found was to build a mapping(Foo => string) and then replace the code with:

function _buildRequestURI(Foo memory foo) public pure returns (string memory) {
    return string(abi.encodePacked(
      BASE_URI,
      "foo=", myMapping[foo.foo]
    ));
  }
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.