Frequently Asked Questions
Last updated
Was this helpful?
Last updated
Was this helpful?
This list was originally compiled by .
This is just the bytecode “data” sent along with the request.
First, a word of warning: Killing contracts sounds like a good idea, because “cleaning up” is always good, but as seen above, it does not really clean up. Furthermore, if Ether is sent to removed contracts, the Ether will be forever lost.
If you want to deactivate your contracts, it is preferable to disable them by changing some internal state which causes all functions to throw. This will make it impossible to use the contract and ether sent to the contract will be returned automatically.
Now to answering the question: Inside a constructor, msg.sender
is the creator. Save it. Then selfdestruct(creator);
to kill and return funds.
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.
Yes, this is possible for all types (even for structs). However, for arrays it should be noted that you must declare them as static memory arrays.
Examples:
substring
, indexOf
, charAt
, etc)?For now, if you want to modify a string (even when you only want to know its length), you should always convert it to a bytes
first:
Yes, you can use abi.encodePacked
:
.call()
less favorable than instantiating a contract with a variable (ContractB b;
) and executing its functions (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 or is not visible and it will do the packing of the arguments for you.
It gets added to the total balance of the contract, just like when you send ether when creating a contract. You can only send ether along to a function that has the payable
modifier, otherwise an exception is thrown.
Getting randomness right is often the crucial part in a crypto project and most failures result from bad random number generators.
The key point is that the calling contract needs to know about the function it intends to call.
Note that filling 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.
Note that merely “creating” the array is free, the costs are in filling it.
Note2: Optimizing storage access can pull the gas costs down considerably, because 32 uint8
values can be stored in a single slot. The problem is that these optimizations currently do not work across loops and also have a problem with bounds checking. You might get much better results in the future, though.
Currently the approach is a little ugly, but there is little that can be done to improve it. In the case of a contract A
calling a new instance of contract B
, parentheses have to be used around new B
because B.value
would refer to a member of B
called value
. You will need to make sure that you have both contracts aware of each other’s presence and that contract B
has a payable
constructor. In this example:
Sure. Take care that if you cross the memory / storage boundary, independent copies will be created:
The call to g(x)
will not have an effect on x
because it needs to create an independent copy of the storage value in memory. On the other hand, h(x)
successfully modifies x
because only a reference and not a copy is passed.
Since version 0.5.0 explicit conversions between fixed-size byte arrays and integers are only allowed, if both types have the same size. This prevents unexpected behaviour when truncating or padding. Such conversions are still possible, but intermediate casts are required that make the desired truncation and padding convention explicit. See Conversions between Elementary Types for a full explanation and examples.
Since version 0.5.0 only hexadecimal number literals can be converted to fixed-size bytes types and only if the number of hex digits matches the size of the type. See Conversions between Literals and Elementary Types for a full explanation and examples.
There are some string utility functions at which will be extended in the future. In addition, Arachnid has written .
See and .
If you do not want it to be safe, you build something similar to the but otherwise, rather use a contract that supplies randomness, like the .
See and .
See .
Integers in Solidity (and most other machine-related programming languages) are restricted to a certain range. For uint256
, this is 0
up to 2**256 - 1
. If the result of some operation on those numbers does not fit inside this range, it is truncated. These truncations can have , so code like the one above is necessary to avoid certain attacks.
If you have more questions or your question is not answered here, please talk to us on or file an .