I'm trying to concatenate a series of strings but I'm getting the following error:
TypeError: Member "concat" not found or not visible after argument-dependent lookup in bytes storage pointer.
--> contracts/Swaper0x.sol:28:23:
|
28 | return string(bytes(api0xUrl)
| ^ (Relevant source part starts here and spans across multiple lines).
Error HH600: Compilation failed
But my concat()
is defined before I call it. What could be the issue? Or the way that I'm calling it is not valid Solidity syntax?
//SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.0;
contract Swaper0x {
string private api0xUrl = 'https://api.0x.org/swap/v1/quote';
string private sellStr = '?sellToken=';
string private buyStr = '&buyToken=';
string private buyAmountStr = '&buyAmount=';
function concat(bytes memory a, bytes memory b) internal pure returns (bytes memory) {
return abi.encodePacked(a, b);
}
function getRequestSELLBUY(
string memory _sellToken,
string memory _buyToken,
string memory _buyAmount
) internal view returns (string memory) {
return string(bytes(api0xUrl) // ---> error starts here
.concat(bytes(sellStr))
.concat(bytes(_sellToken))
.concat(bytes(buyStr))
.concat(bytes(_buyToken))
.concat(bytes(buyAmountStr))
.concat(abi.encodePacked(_buyAmount)));
}
}