TransWikia.com

Deploy bytecode

Ethereum Asked by William Entriken on January 19, 2021

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.

One Answer

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.

Correct answer by Ismael on January 19, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP