mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Corrected FAQ titles
This commit is contained in:
parent
ef6dc52801
commit
a67317928a
@ -10,7 +10,7 @@ Basic Questions
|
||||
***************
|
||||
|
||||
What is Solidity?
|
||||
=============================
|
||||
=================
|
||||
|
||||
Solidity is the DEV-created (i.e. Ethereum Foundation-created),
|
||||
Javascript-inspired language that can be used to create smart contracts
|
||||
@ -28,7 +28,7 @@ There are some `contract examples <https://github.com/fivedogit/solidity-baby-st
|
||||
there should be a `test contract <https://github.com/ethereum/solidity/blob/develop/test/libsolidity/SolidityEndToEndTest.cpp>`_ for every single feature of Solidity.
|
||||
|
||||
How do I compile contracts?
|
||||
=============================
|
||||
===========================
|
||||
|
||||
Probably the fastest way is the `online compiler <https://ethereum.github.io/browser-solidity/>`_.
|
||||
|
||||
@ -71,8 +71,8 @@ several blockchain explorers.
|
||||
Contracts on the blockchain should have their original source
|
||||
code published if they are to be used by third parties.
|
||||
|
||||
Does selfdestruct() free up space in the blockchain?
|
||||
====================================================
|
||||
Does :code:`selfdestruct()` free up space in the blockchain?
|
||||
============================================================
|
||||
|
||||
It removes the contract bytecode and storage from the current block
|
||||
into the future, but since the blockchain stores every single block (i.e.
|
||||
@ -108,8 +108,8 @@ The trick is to create the contract with :code:`{from:someaddress, value: web3.t
|
||||
|
||||
See `endowment_retriever.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/30_endowment_retriever.sol>`_.
|
||||
|
||||
Use a non-constant function (req sendTransaction) to increment a variable in a contract
|
||||
=======================================================================================
|
||||
Use a non-constant function (req :code:`sendTransaction`) to increment a variable in a contract
|
||||
===============================================================================================
|
||||
|
||||
See `value_incrementer.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/20_value_incrementer.sol>`_.
|
||||
|
||||
@ -125,8 +125,8 @@ Its type is the type of the contract. Since any contract type basically inherits
|
||||
:code:`address` type, :code:`this` is always convertible to :code:`address` and in this case contains
|
||||
its own address.
|
||||
|
||||
What is the difference between a function marked constant and one that is not?
|
||||
==============================================================================
|
||||
What is the difference between a function marked :code:`constant` and one that is not?
|
||||
======================================================================================
|
||||
|
||||
:code:`constant` functions can perform some action and return a value, but cannot
|
||||
change state (this is not yet enforced by the compiler). In other words, a
|
||||
@ -139,22 +139,22 @@ with :code:`c.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 funds to you (not using selfdestruct(...)).
|
||||
========================================================================
|
||||
Get a contract to return its funds to you (not using :code:`selfdestruct(...)`).
|
||||
================================================================================
|
||||
|
||||
This example demonstrates how to send funds from a contract to an address.
|
||||
|
||||
See `endowment_retriever <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/30_endowment_retriever.sol>`_.
|
||||
|
||||
What is a mapping and how do we use them?
|
||||
=========================================
|
||||
What is a :code:`mapping` and how do we use them?
|
||||
=================================================
|
||||
|
||||
A mapping is very similar to a K->V hashmap.
|
||||
If you have a state variable of type :code:`mapping (string -> uint) x;`, then you can
|
||||
access the value by :code:`x["somekeystring"]`.
|
||||
|
||||
How can I get the length of a mapping?
|
||||
======================================
|
||||
How can I get the length of a :code:`mapping`?
|
||||
==============================================
|
||||
|
||||
Mappings are a rather low-level data structure. It does not store the keys
|
||||
and it is not possible to know which or how many values are "set". Actually,
|
||||
@ -166,14 +166,14 @@ In this sense, the attribute :code:`length` for a mapping does not really apply.
|
||||
If you want to have a "sized mapping", you can use the iterable mapping
|
||||
(see below) or just a dynamically-sized array of structs.
|
||||
|
||||
Are mappings iterable?
|
||||
======================
|
||||
Are :code:`mapping`'s iterable?
|
||||
===============================
|
||||
|
||||
Mappings themselves are not iterable, but you can use a higher-level
|
||||
datastructure on top of it, for example the `iterable mapping <https://github.com/ethereum/dapp-bin/blob/master/library/iterable_mapping.sol>`_.
|
||||
|
||||
Can I put arrays inside of a mapping? How do I make a mapping of a mapping?
|
||||
===========================================================================
|
||||
Can I put arrays inside of a :code:`mapping`? How do I make a :code:`mapping` of a :code:`mapping`?
|
||||
===================================================================================================
|
||||
|
||||
Mappings are already syntactically similar to arrays as they are, therefore it doesn't make much sense to store an array in them. Rather what you should do is create a mapping of a mapping.
|
||||
|
||||
@ -192,8 +192,8 @@ An example of this would be::
|
||||
}
|
||||
}
|
||||
|
||||
Can you return an array or a string from a solidity function call?
|
||||
==================================================================
|
||||
Can you return an array or a :code:`string` from a solidity function call?
|
||||
==========================================================================
|
||||
|
||||
Yes. See `array_receiver_and_returner.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/60_array_receiver_and_returner.sol>`_.
|
||||
|
||||
@ -203,13 +203,13 @@ This is a limitation of the EVM and will be solved with the next protocol update
|
||||
|
||||
Returning variably-sized data as part of an external transaction or call is fine.
|
||||
|
||||
How do you represent double/float in Solidity?
|
||||
==============================================
|
||||
How do you represent :code:`double`/:code:`float` in Solidity?
|
||||
==============================================================
|
||||
|
||||
This is not yet possible.
|
||||
|
||||
Is it possible to in-line initialize an array like so: string[] myarray = ["a", "b"];
|
||||
=======================================================================================
|
||||
Is it possible to in-line initialize an array like so: :code:`string[] myarray = ["a", "b"];`
|
||||
=============================================================================================
|
||||
|
||||
Yes. However it should be noted that this currently only works with statically sized memory arrays. You can even create an inline memory
|
||||
array in the return statement. Pretty cool, huh?
|
||||
@ -223,8 +223,8 @@ Example::
|
||||
}
|
||||
}
|
||||
|
||||
What are events and why do we need them?
|
||||
========================================
|
||||
What are :code:`event`'s and why do we need them?
|
||||
=================================================
|
||||
|
||||
Let us suppose that you need a contract to alert the outside world when
|
||||
something happens. The contract can fire an event, which can be listened to
|
||||
@ -246,13 +246,13 @@ Internal function calls have the advantage that you can use
|
||||
all Solidity types as parameters, but you have to stick to the
|
||||
simpler ABI types for external calls.
|
||||
|
||||
* external: all, only externally
|
||||
* :code:`external`: all, only externally
|
||||
|
||||
* public: all (this is the default), externally and internally
|
||||
* :code:`public`: all (this is the default), externally and internally
|
||||
|
||||
* internal: only this contract and contracts deriving from it, only internally
|
||||
* :code:`internal`: only this contract and contracts deriving from it, only internally
|
||||
|
||||
* private: only this contract, only internally
|
||||
* :code:`private`: only this contract, only internally
|
||||
|
||||
|
||||
Do contract constructors have to be publicly visible?
|
||||
@ -278,8 +278,8 @@ Is a constructor required?
|
||||
|
||||
No. If there is no constructor, a generic one without arguments and no actions will be used.
|
||||
|
||||
Are timestamps (now, block.timestamp) reliable?
|
||||
===============================================
|
||||
Are timestamps (:code:`now,` :code:`block.timestamp`) reliable?
|
||||
===============================================================
|
||||
|
||||
This depends on what you mean by "reliable".
|
||||
In general, they are supplied by miners and are therefore vulnerable.
|
||||
@ -296,20 +296,20 @@ The value of :code:`now` will be identical to Y and X <= Y <= Z.
|
||||
Never use :code:`now` or :code:`block.hash` as a source of randomness, unless you know
|
||||
what you are doing!
|
||||
|
||||
Can a contract function return a struct?
|
||||
========================================
|
||||
Can a contract function return a :code:`struct`?
|
||||
================================================
|
||||
|
||||
Yes, but only in "internal" function calls.
|
||||
|
||||
If I return an enum, I only get integer values in web3.js. How to get the named values?
|
||||
=======================================================================================
|
||||
If I return an :code:`enum`, I only get integer values in web3.js. How to get the named values?
|
||||
===============================================================================================
|
||||
|
||||
Enums are not supported by the ABI, they are just supported by Solidity.
|
||||
You have to do the mapping yourself for now, we might provide some help
|
||||
later.
|
||||
|
||||
What is the deal with "function () { ... }" inside Solidity contracts? How can a function not have a name?
|
||||
==========================================================================================================
|
||||
What is the deal with :code:`function () { ... }` inside Solidity contracts? How can a function not have a name?
|
||||
================================================================================================================
|
||||
|
||||
This function is called "fallback function" and it
|
||||
is called when someone just sent Ether to the contract without
|
||||
@ -368,16 +368,16 @@ Examples::
|
||||
C c = new C();
|
||||
}
|
||||
|
||||
What is the "modifier" keyword?
|
||||
===============================
|
||||
What is the :code:`modifier` keyword?
|
||||
=====================================
|
||||
|
||||
Modifiers are a way to prepend or append code to a function in order
|
||||
to add guards, initialisation or cleanup functionality in a concise way.
|
||||
|
||||
For examples, see the `features.sol <https://github.com/ethereum/dapp-bin/blob/master/library/features.sol>`_.
|
||||
|
||||
How do structs work?
|
||||
====================
|
||||
How do :code:`struct`'s work?
|
||||
=============================
|
||||
|
||||
See `struct_and_for_loop_tester.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/65_struct_and_for_loop_tester.sol>`_.
|
||||
|
||||
@ -402,8 +402,8 @@ Solidity is character set agnostic concerning strings in the source code, althou
|
||||
utf-8 is recommended. Identifiers (variables, functions, ...) can only use
|
||||
ASCII.
|
||||
|
||||
What are some examples of basic string manipulation (substring, indexOf, charAt, etc)?
|
||||
======================================================================================
|
||||
What are some examples of basic string manipulation (:code:`substring`, :code:`indexOf`, :code:`charAt`, etc)?
|
||||
==============================================================================================================
|
||||
|
||||
There are some string utility functions at `stringUtils.sol <https://github.com/ethereum/dapp-bin/blob/master/library/stringUtils.sol>`_
|
||||
which will be extended in the future.
|
||||
@ -429,8 +429,8 @@ Can I concatenate two strings?
|
||||
|
||||
You have to do it manually for now.
|
||||
|
||||
Why is the low-level function .call() less favorable than instantiating a contract with a variable (ContractB b;) and executing its functions (b.doSomething();)?
|
||||
=================================================================================================================================================================
|
||||
Why is the low-level function :code:`.call()` less favorable than instantiating a contract with a variable (:code:`ContractB b;`) and executing its functions (:code:`b.doSomething();`)?
|
||||
=========================================================================================================================================================================================
|
||||
|
||||
If you use actual functions, the compiler will tell you if the types
|
||||
or your arguments do not match, if the function does not exist
|
||||
@ -445,8 +445,8 @@ Is unused gas automatically refunded?
|
||||
|
||||
Yes and it is immediate, i.e. done as part of the transaction.
|
||||
|
||||
When returning a value of say "uint" type, is it possible to return an "undefined" or "null"-like value?
|
||||
========================================================================================================
|
||||
When returning a value of say :code:`uint` type, is it possible to return an :code:`undefined` or "null"-like value?
|
||||
====================================================================================================================
|
||||
|
||||
This is not possible, because all types use up the full value range.
|
||||
|
||||
@ -495,8 +495,8 @@ No, a function call from one contract to another does not create its own transac
|
||||
you have to look in the overall transaction. This is also the reason why several
|
||||
block explorer do not show Ether sent between contracts correctly.
|
||||
|
||||
What is the memory keyword? What does it do?
|
||||
============================================
|
||||
What is the :code:`memory` keyword? What does it do?
|
||||
====================================================
|
||||
|
||||
The Ethereum Virtual Machine has three areas where it can store items.
|
||||
|
||||
@ -670,8 +670,8 @@ Note2: Optimizing storage access can pull the gas costs down considerably, becau
|
||||
currently do not work across loops and also have a problem with bounds checking.
|
||||
You might get much better results in the future, though.
|
||||
|
||||
What does p.recipient.call.value(p.amount)(p.data) do?
|
||||
======================================================
|
||||
What does :code:`p.recipient.call.value(p.amount)(p.data)` do?
|
||||
==============================================================
|
||||
|
||||
Every external function call in Solidity can be modified in two ways:
|
||||
|
||||
@ -687,8 +687,8 @@ gas and return your 20 Wei).
|
||||
In the above example, the low-level function :code:`call` is used to invoke another
|
||||
contract with :code:`p.data` as payload and :code:`p.amount` Wei is sent with that call.
|
||||
|
||||
What happens to a struct's mapping when copying over a struct?
|
||||
==============================================================
|
||||
What happens to a :code:`struct`'s mapping when copying over a :code:`struct`?
|
||||
==============================================================================
|
||||
|
||||
This is a very interesting question. Suppose that we have a contract field set up like such::
|
||||
|
||||
@ -731,8 +731,8 @@ Can a contract function accept a two-dimensional array?
|
||||
This is not yet implemented for external calls and dynamic arrays -
|
||||
you can only use one level of dynamic arrays.
|
||||
|
||||
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?
|
||||
==============================================================================================================================================================
|
||||
What is the relationship between :code:`bytes32` and :code:`string`? Why is it that :code:`bytes32 somevar = "stringliteral";` works and what does the saved 32-byte hex value mean?
|
||||
====================================================================================================================================================================================
|
||||
|
||||
The type :code:`bytes32` can hold 32 (raw) bytes. In the assignment :code:`bytes32 samevar = "stringliteral";`,
|
||||
the string literal is interpreted in its raw byte form and if you inspect :code:`somevar` and
|
||||
@ -753,8 +753,8 @@ characters) and the second byte (not character) of the utf-8 encoded
|
||||
string, respectively.
|
||||
|
||||
|
||||
Can a contract pass an array (static size) or string or bytes (dynamic size) to another contract?
|
||||
=================================================================================================
|
||||
Can a contract pass an array (static size) or string or :code:`bytes` (dynamic size) to another contract?
|
||||
=========================================================================================================
|
||||
|
||||
Sure. Take care that if you cross the memory / storage boundary,
|
||||
independent copies will be created::
|
||||
@ -782,8 +782,8 @@ to create an independent copy of the storage value in memory
|
||||
:code:`h(x)` successfully modifies :code:`x` because only a reference
|
||||
and not a copy is passed.
|
||||
|
||||
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?
|
||||
==============================================================================================================================================
|
||||
Sometimes, when I try to change the length of an array with ex: :code:`arrayname.length = 7;` I get a compiler error :code:`Value must be an lvalue`. Why?
|
||||
==========================================================================================================================================================
|
||||
|
||||
You can resize a dynamic array in storage (i.e. an array declared at the
|
||||
contract level) with :code:`arrayname.length = <some new length>;`. If you get the
|
||||
@ -812,8 +812,8 @@ The reason for this is that :code:`T[5]` is always an array of 5 :code:`T`'s,
|
||||
no matter whether :code:`T` itself is an array or not (this is not the
|
||||
case in C or Java).
|
||||
|
||||
Is it possible to return an array of strings ( string[] ) from a Solidity function?
|
||||
===================================================================================
|
||||
Is it possible to return an array of strings (:code:`string[]`) from a Solidity function?
|
||||
===========================================================================================
|
||||
|
||||
Not yet, as this requires two levels of dynamic arrays (:code:`string` is a dynamic array itself).
|
||||
|
||||
@ -825,8 +825,8 @@ individual elements. If you want to return the complete array, you have to
|
||||
manually write a function to do that.
|
||||
|
||||
|
||||
What could have happened if an account has storage value/s but no code? Example: http://test.ether.camp/account/5f740b3a43fbb99724ce93a879805f4dc89178b5
|
||||
=========================================================================================================================================================
|
||||
What could have happened if an account has storage value(s) but no code? Example: http://test.ether.camp/account/5f740b3a43fbb99724ce93a879805f4dc89178b5
|
||||
==========================================================================================================================================================
|
||||
|
||||
The last thing a constructor does is returning the code of the contract.
|
||||
The gas costs for this depend on the length of the code and it might be
|
||||
@ -839,8 +839,8 @@ https://github.com/ethereum/wiki/wiki/Subtleties
|
||||
After a successful CREATE operation's sub-execution, if the operation returns x, 5 * len(x) gas is subtracted from the remaining gas before the contract is created. If the remaining gas is less than 5 * len(x), then no gas is subtracted, the code of the created contract becomes the empty string, but this is not treated as an exceptional condition - no reverts happen.
|
||||
|
||||
|
||||
How do I use .send()?
|
||||
=====================
|
||||
How do I use :code:`.send()`?
|
||||
=============================
|
||||
|
||||
If you want to send 20 Ether from a contract to the address :code:`x`, you use :code:`x.send(20 ether);`.
|
||||
Here, :code:`x` can be a plain address or a contract. If the contract already explicitly defines
|
||||
|
Loading…
Reference in New Issue
Block a user