2

I am new to Ethereum, trying to get the hang of using geth and web3js. Looked around and could not find a similar issue, would appreciate some explanation over the following.

I tried to create a transaction using web3js console:

eth.sendTransaction({from:sender, to:receiver, value:amount});

Following a silly mistake, instead of setting the receiver as an address string, I have set it to:

receiver = eth.accounts['public key string here...'];

Obviously, I do not have an account with such an index, so seems like receiver should be undefined and thus sendTransaction throw an error.

However, the transaction did initiate, and created a contract with a seemingly randomly generated address.

I realise that setting a wrong address for receiver will set the funds available to that random address only, making them unspendable. What is the meaning of a transaction to an undefined receiver. Why does it create a contract?

3

You've discovered how contracts are deployed :-)

Sending a transaction to the null address is a special case that causes the transaction's data to be run as bytecode (the contract's constructor). This would normally result in contract code being deployed at that address. In your case it looks like there is no call data, so an empty contract will be created.

Formally, this is how the Ethereum Yellow Paper puts it (section 4.3):

enter image description here

The address is not strictly random, but is generated based on the sender/from address and the sending account's nonce (how many transactions that account has sent in the past).

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.