How to use the Solidity compiler with TestRPC blockchain emulator

I want to interact with my QT application which include a solidity file written in version 0.4.0 , with Testrpc as ablockchain 6.0.3 but I don’t know which version this emulator accept , any one can help me please ,

If you want to compile a file written for 0.4.0 than any version between 0.4.0 and 0.4.26 should work (You might need to adjust the version pragma though if it says exactly 0.4.0 rather than ^0.4.0).

TestRPC states this about the compiler when listing commands:

eth_compileSolidity: If you’d like Solidity compilation in Javascript, please see the solc-js project. Docker.

So I suspect you just need to install solc package via npm (that’s the name for solc-js in npm registry) and use the configuration to tell it which version to use.

I there is a chance to try this in your machine the project is in GitHub - MohamedTaharHAMMI/BubblesOfTrust-BBTrust-
I was install solc and I check the version which is 0.5.16 and I convert the old one but the project sill stopped when opening the solidity file

solc --version
solc, the solidity compiler commandline interface
Version: 0.5.16+commit.9c3226ce.Linux.g++
but this is the solc but now I want to use Testrpc to stored my contract , so the problem id du to the Testrpc it self

What you have is the native Linux binary. TestRPC docs say they use solc-js, which is this: GitHub - ethereum/solc-js: Javascript bindings for the Solidity compiler. You can install it with npm install solc.

This testrpc version is used thereumJS TestRPC v6.0.3 (ganache-core: 2.0.2)

Yes, I was install the same one but the project still not worked , really I want your help

Looking at your README, you’re using which actually redirects to ganache-cli. Looks like the project became Ganache:

Looking for TestRPC?

If you came here expecting to find the TestRPC, you’re in the right place! Truffle has taken the TestRPC under its wing and made it part of the Truffle suite of tools. From now on you can expect better support along with tons of new features that help make Ethereum development safer, easier, and more enjoyable. Use ganache-cli just as you would testrpc.

And Ganache does not support Solidity compilation like TestRPC used to:

Unsupported Methods

  • eth_compileSolidity: If you’d like Solidity compilation in Javascript, please see the solc-js project.

This means it won’t work the way you’re trying to do it. You need to use the compiler yourself and compile the contract into bytecode you can deploy.

If you can use JS directly from Qt, try solc-js. If not, you can invoke the native Linux binary you got with --standard-json option. Here’s the documentation for the input JSON the compiler accepts: Using the compiler > Input description.

And an example of input and compiler invocation:


    "language": "Solidity",
    "sources": {
        "contract.sol": {
            "content": "contract C {}"
    "settings": {
        "outputSelection": {"*": { "*": ["evm.bytecode.object"]}},
        "optimizer": {"enabled": true}
solc --standard-json input.json

I was already install solc-js compiler but the emulator still doesn’t accept the solidity file , I was try much ways but no one success .

what section exactly in my project must be edited [GitHub - MohamedTaharHAMMI/BubblesOfTrust-BBTrust-]
I want your help please

Because the emulator no longer supports compiling Solidity files. Unfortunately you must compile the file yourself and give it already compiled bytecode.

how I can do that , help me please I want to complete the project as soon as possible

Please look at my post above. I gave an example of how you can run the compiler. The details on how to integrate it with your project are up to you. Sorry, but I do not know your code at all and it’s really hard for me to give you a more specific answer.

what about this
You do need the source code, as you have, and one way to get the ABI is to paste it in Remix IDE, compile it, and then click the ‘ABI’ button to copy the ABI into your clipboard.

If you need contract ABI you can simply run

solc --abi <file name>.sol

but I want to call this in a QT instead of this
#define CONTRACT_PATH “/home/asma/Downloads/BBTrust/BCTrustV2/contracts/BCTrustV2.sol”
QVariantList params ;
params.append(FileToString(CONTRACT_PATH)) ;

excuse me what this code will do exactly

and what about truffle

You’ll probably get a better answer if you find the support channel for TestRPC tool or other tools that you are using. As such, this post might be out of topic for the forum.

1 Like