3

Is it possible to write a smart contract that can execute solidity code send to it as data?

  • it's better to detail your questions next time but the answer for this one is No it can't – Badr Bellaj Jul 27 '18 at 20:19
4

Yes and no.

The Solidity compiler isn't available inside the EVM, so there's no way to compile new source code at runtime.

That said, you can compile the Solidity code in advance and pass the compiled byte code to a contract. The contract can't then directly execute that code, but it can deploy it as a new contract and interact with it that way (including using DELEGATECALL to run it in the context of the original contract).

Without knowing your scenario better, it's hard to give more specific advice.

1

In theory you can write an interpreter of solidity and run it inside the EVM.

In practice this is complex because the EVM has some restrictions like block gas limit, or transaction size, this limits how large your contract can be. You can use libraries to leverage contracts size but that will increase the complexity and maintenance of the project.

Also writing a very large project in solidity is a daunting task. There's no specialized IDE for large projects, you have solidity plugins for popular IDEs but they are very simple, there's no refactoring feature.

-1

No that is not possible. Solidity is a static typed language so the logic can only be defined once (before you deploy for the first time).

  • The type system has nothing to do with this. – smarx Jul 28 '18 at 3:22
  • I was not referring to the data types, I was explaining that because a contract is once deployed to the network you cannot edit it since the hashes will not match up between the blocks on the network, as the protocols of the contract have changed. – BlockchainBoy Jul 28 '18 at 4:00
  • The answer you gave said the answer is "no" because "Solidity is a static typed language." Your comment gives a completely different reason (which is also wrong). – smarx Jul 28 '18 at 4:05
  • At least we all learn here :D – BlockchainBoy Jul 28 '18 at 4:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.