I encountered this question and attempted to find an answer on the internet, but I couldn’t find a straightforward explanation. Does it simply “work” like magic?
To create a contract, we must send the contract’s bytecode to the zero address, known as
0x0000000000000000000000000000000000000000. However, how does this process unfold afterward? The zero address isn’t a contract itself, so how does it utilize the bytecode we send to deploy the contract?
As it turns out, even though the zero address is an Externally Owned Account (EOA), the nodes don’t process transactions to it like they do with other EOAs.
The function responsible for applying a new transaction to the state, first checks whether the transaction is sent to the zero address. If it is, it sets the
contractCreationvalue to true.
If the transaction is sent to the zero address (i.e.,
contractCreationis true), instead of invoking the
callfunction in EVM, the
createfunction is called with the msg.data
- Subsequently, this bytecode is executed to obtain the runtime code.
- And then after a gas check, this runtime code is saved at the address that has already been generated.
Kaching!!, your contract is deployed.
NOTE: code snippets are references from geth.