1
votes

I have created a project for a DApp in Solidity language for Ethereum with this structure:

...ReinsuranceProject .....contract .......Reinsure.sol .....library .......Strings.sol

In the contract Reinsure.sol I have imported Strings.sol which is a library, like this: import "../Strings.sol"; This library contains a function which converts bytes to string. In my main contract, Reinsure.sol I have added these rows: using StringsLib for bytes; (StringLib its because the library itself is called like this not the file) and in another method I want to return varBytes.toString();

However, when compiling the project I get this error:

TypeError: Member "toString" not found or not visible after argument-dependent lookup in bytes memory\n

The method toString is declared like so:

function toString(bytes32 x) constant internal returns (string)

Compiler version of Solidity pragma solidity "0.4.25";(I am using Visual Studio Code which has an extention for Solidity)

Questions are: If the problem is in the import, what is the right way to import the Strings.sol library with the specified project structure? If not, am I naming the classes in the wrong way and if so how to fix it? Is there a way to make a config file for the paths to make this easier?

I would really appreciate your help, and thank you in advance!

1

1 Answers

0
votes

You're mixing types. bytes is a dynamic array while bytes32 is static. Change using StringLib for bytes to using StringLib for bytes32.

Example:

pragma solidity ^0.4.25;

library StringsLib {
    function toString(bytes32 self) constant internal returns (string) {
        // Convert bytes32 to string
    }
}

Contract:

pragma solidity ^0.4.25;

import "./StringsLib.sol";

contract LibraryClient {
    using StringsLib for bytes32;

    function doSomething(bytes32 x) public constant returns (string) {
        return x.toString();
    }
}