0

I was using remix for basic solidity. Can someone explain if I'm using string.concat() why is it giving that error even if both types are string. I tried the Docs as well but it gives the same error.

from solidity: TypeError: Type bytes memory is not implicitly convertible to expected type string memory.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract test{
    function hi(string memory name) pure public returns(string memory){
        string memory greetings = string.concat("Hello", name);
        return greetings;
    }
}

1 Answer 1

1

The string.concat function was 'fixed' to take and return strings in solidity v0.8.12, so you should change the pragma solidity ^0.8.0 to pragma solidity ^0.8.12, for example:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;

contract test {
    function hi(string memory name) pure public returns(string memory){
        string memory greetings = string.concat("Hello", name);
        return greetings;
    }
}

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.