0

I just stated working with Ethereum and new in it, so maybe my question will sound not so smart, but is there any way of calling C++ code from Ethereum contract?

For instance I can call C++ from PHP like that

exec("/path/to/your/binary $var1 $var2", $output);

Is there similar mechanism?

Maria
  • 515
  • 4
  • 17
  • You cannot run C++ code directly, it must be compiled before. – user0042 Aug 04 '17 at 14:23
  • @user0042 Yes, I understand it. Do you know how to do it? I mean how will code look like? Is it possible at all? – Maria Aug 04 '17 at 14:27
  • I admittedly don't know Euthereum, but doesn't the code need to run on the (distributed) Euthereum virtual machine? The C++ would have to be compiled to the same target bytecode, no? – Cameron Aug 04 '17 at 14:33
  • 1
    Solidity, by design, cannot use external libraries. –  Aug 04 '17 at 14:34

1 Answers1

1

The smart contract you coded with Solidity gets compiled in Machine Language code for the EVM, the Ethereum Virtual Machine. This byte code gets injected inside the Blockchain, and you can interact with it throught transactions / calls. Everything that is happening inside the EVM cannot access what is happening outside the EVM.

You cannot push another language code inside the Blockchain and expect it to work. If you want to achieve this, you have to code the software that will make the bridge between the C++ code and your smart contract that is on the Blockchain. But remember that as long as you cannot prove to the rest of the Blockchain the fairplay of what your C++ program achieved, the informations in you smart contract will be worth nothing. What is interesting about the EVM is that every action is happening on the Blockchain, and everyone can see what is happening.

But it all depends on what you are trying to achieve or build !

mortimr
  • 111
  • 4
  • Thank you very much for your detailed answer! Yes, I really need to call C++ library and will need to build bridge between the C++ code and smart contract. I would highly appreciate if you can give me link to some example. But thanx anyway =) – Maria Aug 07 '17 at 08:51
  • 1
    Use geth (go-ethereum) to connect to the blockchain. Then search for a c++ library that connects to geth and communicates with the node in order to be able to interact with the Blockchain directly from your c++ code. – mortimr Aug 07 '17 at 09:07
  • 1
    @lulian Rotaru Thanx! Will check it. Have a nice day! – Maria Aug 07 '17 at 10:01