0

I have a compiled contract (actually it's just arbitrary data) that I would like to store as an account.

It is possible to store this as a new account using web3js?

I do NOT have a constructor function. I just have the raw bytes.

Or is there some way I can translate the raw bytes into a constructor function that I can run?


My plan is to run this with Metamask.

  • I don't think that is possible because the compiler doesn't compile the contract but rather compiles a transaction which will then create the contract. May I ask why you want to store arbitrary data on the blockchain? – Grunzwanzling Feb 23 '18 at 23:18
  • Maybe start a dark web – William Entriken Feb 24 '18 at 3:18
  • It should be possible but you need an special constructor that returns your data as contract code. For more technical details see this article medium.com/@hayeah/…. – Ismael Feb 24 '18 at 5:54
  • @Full Decent Starting a dark web will not work. Storing data on the blockchain costs literally millions of dollars per GB. Use an already existing distributed dark web solution like IPFS! – Grunzwanzling Feb 24 '18 at 10:21
  • @Ismael Thank you. I would accept that as the answer – William Entriken Feb 24 '18 at 17:51
0

It should be possible but you need an special constructor that returns your data as contract code. From the article Diving Into The Ethereum VM Part 5 — The Smart Contract Creation Process

The deploy code has two main purposes:

  • Runs the constructor function, and sets up initial storage variables (like contract owner).
  • Calculates the contract code, and returns it to the EVM.

The deploy code generated by the Solidity Compiler loads the contract from bytecode into memory, then returns it as the contract code.

But the data stored like this is not directly accessible. You can access them with web3.eth.getCode you cannot modify it, nor make more advanced queries.

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.