Mako Shan

Mako 是一名密码朋克爱好者
这里是我记录生活和成长的地方

联系我的微信号
👏欢迎一起交流学习

Ethereum 101

How do I see the status of the ethereum network?
http://stackoverflow.com/questions/33801652/how-can-i-see-the-status-of-the-ethereum-network

How can I explore accounts, transactions and blocks?
http://stackoverflow.com/questions/33801652/how-can-i-see-the-status-of-the-ethereum-network

I want email alerts for my accounts. How do I get them?
https://etherscan.io/ has a cool feature for that. https://frontier.ether.camp apparently does to, but I haven’t tried it.

Where can I trade/buy Ethers?
http://stackoverflow.com/questions/33727658/what-is-the-easiest-way-to-buy-ether

How can I check the balance of an address?
http://stackoverflow.com/questions/32312884/how-do-i-get-the-balance-of-an-account-in-ethereum

function checkAllBalances() { var i =0; eth.accounts.forEach( function(e){ console.log(" eth.accounts["+i+"]: " + e + " \tbalance: " + web3.fromWei(eth.getBalance(e), "ether") + " ether"); i++; })}; checkAllBalances();

Where can I find a denomination converter?
http://ether.fund/tool/converter

I only need the password to access an Ethereum account, right?
http://stackoverflow.com/questions/33801791/i-have-my-ethereum-account-address-and-password-thats-all-i-need-to-access-it
General
✓?
Task/Question
Answer

What is Ethereum?
Obviously, this is a very broad question, but here’s how I usually ELI5 to my non-technical friends…
Bitcoin says “Send X from A to B”. Ethereum says “Send X from A to B if J and K but not L”
Further, where all bitcoins always reside in the accounts of its participants, Ethereum has a second type of account: contracts. A contract can hold value and do something with it based on conditionals. For instance, a hundred people could pay $1 into a raffle contract which is rigged to pay out to a random user on the 100th payment.

Ethereum has two types of accounts, “normal” (think Bitcoin) and contracts. Given only a hash, is it possible to tell which type an account is?
http://stackoverflow.com/questions/33801892/given-an-ethereum-account-hash-is-it-possible-to-tell-whether-it-is-a-normal/

Gas is a new concept. What is it? And what is the relationship between “gas/startgas” and “gasprice”?
http://stackoverflow.com/questions/33802037/in-ethereum-what-is-gas-how-is-it-used-and-what-is-the-difference-between

Does the current block gas limit apply to each transaction only or all transactions in the block?
All transactions in the block.
For instance, right now, with a gas limit of 3.14 million, 10x transactions of 300,000 could be processed in a block. 2x transactions of 3 million could not. As I understand it, one would get pushed to a subsequent block. I don’t know which is chosen for processing first.

When will the gas limit get raised?
http://stackoverflow.com/questions/33802172/the-ethereum-gas-limit-seems-prohibitively-low-will-it-ever-be-raised-if-so-w

I’ve seen references to “shannon” as an ETH denomination (= .001 szabo), but it doesn’t appear on http://ether.fund/tool/converter. What’s with that?
Mention of “shannon” appears here: https://blog.ethereum.org/2015/08/04/the-thawing-frontier/

Also on Wikipedia: https://en.wikipedia.org/wiki/Ethereum

Ursium answer: https://www.reddit.com/r/ethereum/comments/3g8grm/ether_unit_converter_wei_finney_szabo_btc/
Ada = 103 Wei, Babbage = 106 Wei, Shannon = 109 Wei, Szabo = 1012 Wei, Finney = 1015 Wei,
Ether = 1018 Wei. In other words, Shannon == 1 Gwei == 1 billion Wei

I’ve seen references to a GlobalRegistrar in various places -- an “official” name registration to map names to addresses (like DNS). Where is it and how do I use it?
Apparently it hasn’t been released yet for frontier according to github user “rifikki”. If you’ve seen these registrar attempts/discussions around, they’re either “unofficial” or were used during testing and are no longer active. I think the DEVs may be trying to work out how to prevent squatting first.

There is a gitter channel here: https://gitter.im/ethereum/go-ethereum/name-registry but it’s unclear if it’s still active.

I’ll post usage information here when it becomes available.

11/20/2015 - There was some discussion of this at DEVCON1 (day 3 or 4, if I’m not mistaken). There is thought/effort surrounding name registration, but it’s pretty complicated stuff.

How many ethers were purchased during the pre-sale, exist now or will exist?
From ursium: "There is no maximum. 60,102,216 ethers were created during the sale, plus 2x pools of 9.9% each. 26% of 60,102,216 will be created through mining every year. This means that 15,626,576 will be created every year on top of the 60m and the two pools.

After a while, 15,626,576 ether won't represent much of the total ether available, making the system dis-inflationary (i.e., inflation perpetually trending towards 0 but never reaching it)."

What is proof of stake and when will Ethereum switch to it?
http://stackoverflow.com/questions/33802343/when-will-ethereum-switch-to-proof-of-stake

What is a private testnet, why would I want it, and how do I set it up?
http://stackoverflow.com/questions/33826018/in-ethereum-what-is-a-private-testnet-why-would-i-want-it-and-how-do-i-set-it/

How do I know that a piece of source code is actually what’s published to the blockchain in a contract?
http://stackoverflow.com/questions/33798205/how-to-get-or-verify-the-source-code-of-a-contract
Mining
✓?
Task/Question
Answer

Is it possible to mine ethereum with only a CPU?
Yes, but it would be pointless. The difficulty is already way too high for that. You’ll need a fairly powerful GPU to do it.

How much system RAM does a computer need to mine Ethers?
I cheaped out when I was building and put 4GB in there. Not enough. Added another 2GB and it worked. The reason is the system RAM has to hold a large file in memory in order to do its thing.

Would my GPU be any good at mining ethereum?
Check out this amazing GPU efficiency breakdown.
https://docs.google.com/spreadsheets/d/1s5SaThZ5eOSAiVMpmuIjz-_YjIlcxttAzKuWKAbczds/edit#gid=0

What mining pools are out there to join?
Check out https://etherchain.org/statistics/miners
✓-
What does it mean that a miner can “choose” information to provide or which transactions to include?
Successfully discovering (mining) a block grants certain privileges to the miner. They get to choose the gas limit for the next block, for instance (within +/- 1/1000 of the last block). They also provide the timestamp (which affects the alias “now”, obviously) and probably some other input as well. Conversely, there are variables they cannot alter. A list of global variables is available here: https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#global-variables

If you have a definitive list of which of these miners can and cannot modify/include, please email it to me.

What order are tx processed in? Do miners get to decide?
Miners decide the order. Geth, by default, orders them by highest gas price until the block is filled.

Edit: 10/18/2015 - I’m not sure this is true. Recently, I’ve been sending a bunch of transactions with a gas unit value of 3,000,000, just short of the 3.14 million per-block (cumulative) limit. These transactions have typically taken much longer to be mined than those with lower gas unit values. I believe this is because miners are trying to maximize the amount of money they get paid for mining a block. If you were a miner, which would you rather do?

A: Include a bunch of transactions with small possible gas usage -- OR -- B: Include 1 possibly big transaction near the 3.14 mil limit?

If you choose B, then you’ll probably end up including only 1 transaction in your block. There isn’t room for any more. But that transaction, which has a possible gas usage of up to 3.14 million and could make you rich (lol), might only actually use 10k gas, and you’ll earn almost no money for processing the block. This is why txs with high possible gas usage are deprioritized and postponed. The miner doesn’t know if they’ll really pay out.
Geth
✓?
Task/Question
Answer

What is geth?
“geth” is the Go-language client program that runs a node on your computer. That is, it gathers the entire ethereum ledger and listens for new blocks. It has a console that allows you to interact with the ethereum network. “web3” (which you’ll see in a lot of the examples) is the Javascript library that geth uses for most commands.

The geth-like program in the C++ implementation is called “eth” and the Python one is called “pyeth”. I haven’t used them as much, but they are similar in function.

How do I install geth?
This link is called “Building Ethereum” but it has links to instructions for getting the binaries through various package managers. I highly recommend using a package manager so you automatically get the most up-to-date versions of the software. https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum

Ok. I’ve installed geth. How do I create a new account?
If you bought during the presale (aka the Ethersale) back in 2014, then you should have a .json file with your account info. Use this from the command line (close geth if you have already started it):
$> geth wallet import /path/to/my/presale.wallet
Otherwise, create an entirely new account with this command:
$> geth account new
More info here: https://ethereum.gitbooks.io/frontier-guide/content/managing_accounts.html

How do I change my account password?
From a system terminal window, type
$> geth account update 0xabc123… (no quotes)
It’ll ask you for your existing password. Enter it. Then enter the new password twice. DO NOT FORGET IT.
Unlocking account 0xabc123... | Attempt 1/3
Passphrase:
Account '0xabc123...' unlocked.
Please give a new password. Do not forget this password.
Passphrase:
Repeat Passphrase:
If you have multiple accounts (you can check this by typing eth.accounts in your geth console), you can use the update to rearrange your account list. Whichever one you update will go to the end of your list. The rest will shift left.

How do I send ether to an address?
The following command will send 1.75 ether from your first account to your second account.

web3.eth.sendTransaction({from:eth.accounts[0],to:eth.accounts[1],value:web3.toWei(1.75,"ether")});

Geth makes too much log noise and I can’t see what I’m doing.
Start geth with ‘geth --verbosity “2” console’
OR avsa: “In my opinion the best way to solve that is, on most terminals, open a second window and type on there "geth attach" so that all the logs will appear on the secondary window” (That is, “geth” and then “geth attach”. The “geth attach” window will automatically drop into console.) (This is what I do now.)

How can I get an immediate return value from a non-constant (transactional) method in console
9/2/2015 Not yet possible. First, do your sendTransaction to the non-constant method, wait for the transaction to be mined (i.e. take place), then use a separate constant method to retrieve the value you want.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/20_value_incrementer.sol

Inside geth, display the amount of gas expended on a sendTransaction call
var receipt = web3.eth.getTransactionReceipt(), then display receipt.

How do I send parameters to a non-constant function with sendTransaction?
for
function increment(int howmuch, int _customvalue) { … }
do this:
incrementer3.increment.sendTransaction(3,9, {from:eth.coinbase,gas:1000000});
Make sure your gas payment is high enough.

How do you interact with a contract that was published in the past?
http://stackoverflow.com/questions/33839074/in-ethereum-how-do-i-interface-with-a-contract-on-the-blockchain

Sometimes my contracts compile and deploy and I can sendTransaction to its non-constant functions, but the logic in the function doesn’t seem to execute. No errors.
Increase how much gas you’re sending along. This caused me big headaches until I finally realized it 2 days later.
Ex: incrementer3.increment.sendTransaction(3,9, {from:eth.coinbase,gas:1000000});

9/12/2015: I also got this erroneous behavior when I deployed a contract with an array creation and tried to write a value in the array at an index that didn’t exist. I suspect there are many ways you can have failed transactions. Check your code.

What is the “logs” array in a transaction receipt?
Logs come in to play when Events are fired within your contracts.
This is what a transaction receipt looks like:
{
blockHash: "0xdcb73cb28e7baaeb1b24e6aeae4e46f7ffea0ee3b5bf1afd8ae5f0eb2312954f",
blockNumber: 224644,
contractAddress: "0x37f18e3eef435e80f490c0beafd9cf0365686658",
cumulativeGasUsed: 161639,
gasUsed: 161639,
logs: [],
transactionHash: "0x3411264089ee335cd8e3af7e2e5de775a1088a40853a8576b215e221f5890e5e",
transactionIndex: 0
}

And here is a log object caught by web3 -> contractname.allEvents(function (error, log) { // callback. do something };

{ address: '0x429e434f0de48b2a75b7147105582d61bb4ea8ec',
blockNumber: 412525,
logIndex: 0,
blockHash: '0x7e0af6c777c6a34438207fdf81bfea4b6827e2f34b269072e0c1a82944c3e48d',
transactionHash: '0xb4af9d9168c9b1ea95021f9e89c5776373d6fbdeffff1f43fd4a83b388c346b1',
transactionIndex: 0,
event: 'TileChanged',
args:
{ col: { [String: '5'] s: 1, e: 0, c: [Object] },
row: { [String: '9'] s: 1, e: 0, c: [Object] } }
}

In this example, I chose to return col and row with my solidity event, “Event TileChanged(uint8 row, uint8 col);”

What is the “transactionIndex” in a transaction receipt?
{
blockHash: "0xdcb73cb28e7baaeb1b24e6aeae4e46f7ffea0ee3b5bf1afd8ae5f0eb2312954f",
blockNumber: 224644,
contractAddress: "0x37f18e3eef435e80f490c0beafd9cf0365686658",
cumulativeGasUsed: 161639,
gasUsed: 161639,
logs: [],
transactionHash: "0x3411264089ee335cd8e3af7e2e5de775a1088a40853a8576b215e221f5890e5e",
transactionIndex: 0
}
9/12/2015: My guess is it’s for use in batch requests. The second tx executed in the batch would be “1”, etc. I’ll check this off once I’ve confirmed it.

What happens if you delete the ~/.ethereum/dapp directory/database and restart?


If I send a transaction and it runs out of gas before completion, what happens?
The miner gets the gas payment. You’re SOL. If you thought the transaction might execute at some point in the future when the block gas limit goes up and the tx becomes possible, that’s a big negatory, good buddy. It will not excute in the future.

What is the difference between .call() and .sendTransaction()?
.call() is basically the same as .sendTransaction() except that .call() is for constant methods where .sendTransaction() is for non-constant (transactional) methods.

“But I thought we use ‘contractvariable.someMethod()’ for constant calls. You said so in the previous answer!” That’s true. But ‘contractvariable.someMethod()’= ‘contractvariable.someMethod.call()’, So why do we need .call() at all? For asynchronicity. Some constant methods may take a long time to complete. This’ll hang your execution. No gouda. To make these calls asynchronous, include a callback function as the last parameter to .call() like this:

etheria.getElevations.call(function(error, result) { … }); // The fn will execute on completion, result is the return value
Contracts - Compilation and publishing
✓?
Task/Question
Answer

What is Solidity?
Solidity is the DEV-created (i.e. Ethereum foundation-created), Javascript-inspired language used to create contracts. There are other languages you can use as well (LLL, Serpent, etc), but my understanding is that Solidity is the “official” contract language for now, which is why my examples are written in it.
Solidity contracts can be compiled a few different ways (see below) and the resulting output can be cut/pasted into a geth console to deploy them to the Ethereum blockchain.
My solidity repository of samples is here: https://github.com/fivedogit/solidity-baby-steps/blob/master

How do I compile contracts?
Use chriseth’s Online, Realtime Solidity Compiler. It’s awesome. Ignore all other advice. :)
https://chriseth.github.io/browser-solidity/

Edit: You can use the “solc” binary which comes with cpp-ethereum to compile contracts OR an emerging option is to use Mix, the IDE. I’ve found that Mix will provide compilation error information that the online compiler doesn’t (and vice-versa), so you might want to use a -- ahem -- mix of compilers. Wordplay!

Create and publish the most basic contract possible
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/05_greeter.sol
Edit: That isn’t actually the simplest contract possible, but it’s still easy enough for a beginner to understand.

Get contract address in the console after publishing
The address shows up in the geth prompt after publishing if you use the online solidity compiler.
https://chriseth.github.io/browser-solidity/
✓-
Is it possible to do something on a specific block #? (e.g. publish a contract or execute a transaction)
Transactions are not guaranteed to happen on the next block or any future specific block.
Imifos on StackOverflow: “You can never be sure that your transaction is included in a block since this is decided by the miner and not the transaction submitter.”
Whether or not a contract creation is guaranteed on the next block or a future specific block, I’m not sure.

What is the transaction “payload”?
This is just the bytecode “data” sent along with the request. I saw this while messing around on etherchain, ex:
https://etherchain.org/tx/0x3411264089ee335cd8e3af7e2e5de775a1088a40853a8576b215e221f5890e5e
and
https://etherchain.org/tx/0x232792abb77b7cb15c4f4c8979c999af0c4c278a149334e7ab6b239811717487
The first is a contract creation (larger payload) and the second is a “kill” sendTransaction.

Is there a decompiler available?


Does contract.suicide() free up space in the blockchain?
No. Although the Contract Tutorial says “The inherited characteristic ‘mortal’ simply means that the contract can be killed by its owner, to clean up the blockchain…”, chriseth has clarified that it does not “clean up” in the sense of removing blockchain bloat / freeing up space.

I made this mistake early on (cheap gas, not wanting to figure out how to set up a private chain, wanting to test under “real world” conditions, etc) and feel bad about it. Use the public testnet or a private chain.
Contracts - Basic concepts

Create a contract that can be killed and return funds
Inside a constructor, msg.sender is the creator. Save it. Then suicide(creator); to kill and return funds.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/05_greeter.sol

Note that if you “import ‘mortal’” at the top of your contracts and declare “contract SomeContract is mortal { …” and compile with a compiler that already has it (which includes https://chriseth.github.io/browser-solidity/ ), then kill() is taken care of for you. Once a contract is “mortal”, then you can contractname.kill.sendTransaction({from:eth.coinbase}), just the same as my examples.

Store ether in a contract
The trick is to create the contract with {from:someaddress, value: web3.toWei(3,”ether”)...}
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/30_endowment_retriever.sol

Use a non-constant method (req sendTransaction) to increment a variable in a contract
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/20_value_incrementer.sol

Get contract address in Solidity
The global variable ‘this’ is the contract address.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/15_basic_info_getter.sol

What is the difference between a function marked “constant” and one that isn’t?
“constant” methods can perform some action and return a value, but cannot change state. In other words, a constant method can’t save or update any variables within the contract or wider blockchain. These methods are called with contractvariable.someMethod(...) from geth.

“non-constant” methods (those lacking the “constant” declaration) must be called with contractvariable.someMethod.sendTransaction({from:eth.accounts[x], gas: 1000000}); That is, because they can change state, they have to have a gas payment sent along to get the work done.

Get a contract to return its balance funds to your coinbase (not using suicide(...)).

This example demonstrates how to send funds from a contract to an address.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/30_endowment_retriever.sol

What is a mapping and how do we use them?
A mapping is just a K->V hashmap. variable[“somekeystring”] gives you the value of a string-> value map, e.g.

Are mappings iterable?
9/2/2015 Not yet. DEV chriseth: “I would use a mapping key -> index and put your [keys] into an array.”
9/11/2015 christian: “This is not possible by design, as the keys are not even stored in the mapping. More complex (read: expensive) datastructures like the iterable mapping (https://github.com/ethereum/dapp-bin/blob/master/future_solidity/iterable_mapping.sol)
will be available once the compiler supports templates and libraries.”

Can you return an array from a solidity function call?
9/12/2015 Yes. See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/60_array_receiver_and_returner.sol

How do you represent double/float in Solidity?
9/2/2015 You can’t yet.

Is it possible to in-line initialize an array like so: string32[] myarray = {“a”, “b”};
9/2/2015 Not yet.

What the hell are events and why do we need them?
Let’s say that you need a contract to alert the outside world when something happens. The contract can fire an Event, which can be listened to from web3 (inside geth or a web application).

What are the different function visibilities?
public - all (This is the default)
private - only this contract
internal - only this contract and contracts deriving from it
external - Cannot be accessed internally, only externally.

see https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#visibility-specifiers

Do contract constructors have to be publicly visible?
No. Setting to “private” works. Not sure what ramifications that may have later, though.

Can a contract have multiple constructors? If so, are they all called at creation time?
No. It appears that there cannot be multiple “function ContractX() {}” declarations in the same contract, regardless of input or output values.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/40_multiple_constructor_test.sol

Is a constructor required?
No. If there is no constructor, a generic one without arguments and no actions will be inferred.

Are timestamps (now, block.timestamp) reliable?
No. They are supplied by miners and are therefore vulnerable. Several other values are supplied too. The best source of randomness (according to vbuterin) is the current block hash since it can’t be known beforehand.
Example: https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/35_coin_flipper.sol

Can a contract function return a struct?
9/2/2015 Yes, but only on “internal” functions for now.

What’s the deal with “function () { blah blah; }” inside Solidity contracts? How can a function not have a name?
9/11/2015: chriseth: “[The unnamed function] is called if no data is provided (e.g. using contractName.send()), if a non-existing function is called on the contract (i.e. you messed up your contract types) or if a raw transaction is sent to the contract.” There can only be one unnamed function per contract.
Source: https://github.com/ethereum/go-ethereum/wiki/Contract-Tutorial#the-code-1

9/28/2015: Interesting side note. I guess I said it above, but the unnamed function is called every time a contract-to-contract send() is sent to the contract. This has several implications, one of which is that if your unnamed function requires too much gas, then contract-to-contract send() could be rendered unusable.

Is it possible to send parameters to an unnamed function?
:4:14: Error: Fallback function cannot take parameters.
function (int8 x, int8 y) constant returns (bool)
^--------------^

Can top-level contract variables be initialized in-line? contract Blah { int x = 7; function Blah() {} }
Yes, for single-value basic types. No for arrays and structs. Ex: “uint8[4] tester = {0,1,2,3};” will not compile.

What is the “modifier” keyword?
Has to do with defining extra “public”, “private”-like declarations
See https://github.com/ethereum/wiki/wiki/Solidity-Tutorial#function-modifiers
and https://github.com/ethereum/dapp-bin/blob/master/library/features.sol

How do structs work?
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/65_struct_and_for_loop_tester.sol

How do for loops work?
Exactly like Javascript, except you have to declare the counter type rather than “var”. I haven’t tested this, but I have a feeling you’d get major breakage if you tried to use, say, uint8 and counted above 255. Watch for it.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/65_struct_and_for_loop_tester.sol

What charset does Solidity use?
Looks like just basic ASCII. ¥, ž, etc (extended ASCII) and мỹŋαмẻїš (UTF-8) all failed compilation when trying to use them as variables.
Solidity “string” types are UTF-8, however.

What’s up with contract/transaction logging. What is it and what can we do with it?

✓-
What are some examples of basic string manipulation (substring, indexOf, charAt, etc)?
somevar[0] = "0" does not work.
More to come…

9/17/2015: stringUtils are in the works. https://github.com/ethereum/dapp-bin/blob/master/library/stringUtils.sol

Can I concatenate two strings?
No. I assume that’ll come with time, but I have heard no official word on that.

I was instructed that using

.call() or .send() is less favorable than instantiating a contract with a variable (ContractB b;) and executing its methods (b.doSomething();). Why?
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_ping.sol
and https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_pong.sol
as an example of the latter. I don’t know why the former is discouraged or considered suboptimal right now.

Update 9/22/2015: I tried to get address.send() to send wei from one contract to another today and couldn’t get it to work. I’m talking to the devs now to see what’s going on.

Is unused gas automatically refunded?
Yes and it is immediate.
✓-
When returning a value of say “uint” type, is it possible to return an “undefined” or “null”-like value?
It looks like the return value is always numeric (unlike Javascript), and would default to 0 in such cases. Please let me know if I’m wrong.

Are comments included with deployed contracts and do they increase req. deployment gas?
No. Adding a shit-ton of comments to a contract did not change its gas deployment cost, which means the comments are not included. (If storage of comments were allowed, they would have to cost gas as they would increase blockchain bloat.)

What happens if you send ether along with a function call to a contract?
It gets added to the total balance of the contract, just like when you send ether when creating a contract.
✓-
Is it possible to get a tx receipt for a transaction executed contract-to-contract?
If you know the transaction hash, yes, using the same web3 console command from the “geth” section above. And you can look that hash up using a blockchain explorer like http://etherchain.org.

Can you get it programmatically? I don’t know.
✓-
What is the memory keyword? What does it do?
http://stackoverflow.com/questions/33839154/in-ethereum-solidity-what-is-the-purpose-of-the-memory-keyword/

Note: It seems like function-level variables should ALWAYS be declared as memory types, so I’m not sure why either (a) memory is not automatically implied for variables declared within functions or (b) not enforced by the compiler. I’m trying to get further information about this.

Can a regular (i.e. non-contract) ethereum account be closed permanently like a contract can?
No.
Contracts - Slightly more advanced concepts

How do you get a random number in a contract? (Implement a self-returning gambling contract.)
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/35_coin_flipper.sol


Get return value from non-constant method from another contract

The key point is that the calling contract needs to know about the method it intends to call.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_ping.sol
and https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_pong.sol

Get contract to do something when it is first mined
Use the constructor. Anything inside it will be executed when the contract is first mined.
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/50_replicator.sol

Get contract to do something on a specified Block #
If we’re talking about deploying a contract and then, in a purely decentralized manner, having it execute something when a block happens… not possible.
You could obviously use web3 to call a function from outside, but that adds centralization.

Can a contract create another contract?
Yes. See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/50_replicator.sol
Note that contracts of a cyclical nature are currently impossible. Let me know if you find a way around this because it’ll allow me to build a cron-like contract.

How do you create 2-dimensional arrays?
See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/55_2D_array.sol
Note that a 10x10 square of uint8 + contract creation took more than 800,000 gas at the time of this writing. 17x17 took 2,000,000 gas. With the limit at 3.14 million… well, there’s a pretty low ceiling for what you can create right now.

From the “Contract Tutorial”:
p.recipient.call.value(p.amount)(p.data);
What is up with that syntax?


Can a contract function accept a two-dimensional array?
It looks like the compiler chokes when you try. “Type error: Internal type is not allowed for public and external functions.” I’m working around it by sending a single-dimensional array, and programming the receiving function to handle it like a 2D array.

What is the relationship between bytes32 and string? Why is it that ‘bytes32 somevar = “stringliteral”;’ works and what does the saved 32-byte hex value mean?


Can a contract pass an array (static size) or string or bytes (dynamic size) to another contract?
Not yet on both counts. The first is definitely a bug. See https://github.com/ethereum/solidity/issues/78
I don’t know if dynamic sized-array/string passing is supposed to be supported, but it does not work either.

See https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/46_array_passer.sol
and https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/47_string_passer.sol

What is CALLCODE and how is it used?


Sometimes, when I try to change the length of an array with ex: “arrayname.length = 7;” I get a compiler error “Value must be an lvalue”. Why?
http://stackoverflow.com/questions/33839122/in-ethereum-solidity-when-changing-an-array-length-i-get-value-must-be-an-lva/
Ancillary projects

What is Mist?
Mist is the upcoming ethereum-enabled web browser, based on Chromium. At the moment, Mist development is focused on the gui-wallet aspect, which requires development of a light client. In general, Mist is a top development priority for the Ethereum project, as a whole.

Mist will allow direct interaction between your Ethereum account and Dapps running on the blockchain which will, in turn, allow very powerful things to happen. You’ll be able to log into websites (that support it) with your Ethereum account, for instance.

For a more pedestrian example, whereas now you have to write commands in the console to interact with, say, a roulette contract, with Mist, you’ll be able to simply drag and drop chips and then click “spin wheel”.

It is part of the cpp-ethereum project.

What is Mix?
Mix is an IDE (an application in which you write programs) written specifically for Ethereum/Solidity.

It is part of the cpp-ethereum project.
✓-
What is Swarm?
Storage in the blockchain is expensive. Swarm is an upcoming solution designed to allow larger chunks of decentralized storage similar to BitTorrent. These chunks will be accessed in a manner similar to FTP but with hashes instead of hostname/directory locations.

In order to decrease latency and cost, Swarm uses a different storage paradigm than Ethereum itself. Namely, nodes do not have to keep Swarm data (as opposed to ethereum where each node MUST keep everything). More info here: https://github.com/ethereum/cpp-ethereum/wiki/Swarm

NOTE: I seem to recall DEV discussion that Swarm is not a top priority at the moment or even much of a priority at all. I can’t find this information now, though, and my memory has been known to be wrong before. So take this with a grain of salt.

1
Emacs is Sexy
目录