mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
96fae0c220
Move warning Updates from feedback Link to security note and fix link rendering Move solution to security docs and turn warning to a warning
97 lines
3.2 KiB
ReStructuredText
97 lines
3.2 KiB
ReStructuredText
###########################
|
|
Frequently Asked Questions
|
|
###########################
|
|
|
|
This list was originally compiled by `fivedogit <mailto:fivedogit@gmail.com>`_.
|
|
|
|
|
|
***************
|
|
Basic Questions
|
|
***************
|
|
|
|
If I return an ``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 are some examples of basic string manipulation (``substring``, ``indexOf``, ``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. In addition, Arachnid has written `solidity-stringutils <https://github.com/Arachnid/solidity-stringutils>`_.
|
|
|
|
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::
|
|
|
|
pragma solidity >=0.4.0 <0.6.0;
|
|
|
|
contract C {
|
|
string s;
|
|
|
|
function append(byte c) public {
|
|
bytes(s).push(c);
|
|
}
|
|
|
|
function set(uint i, byte c) public {
|
|
bytes(s)[i] = c;
|
|
}
|
|
}
|
|
|
|
|
|
Can I concatenate two strings?
|
|
==============================
|
|
|
|
Yes, you can use ``abi.encodePacked``::
|
|
|
|
pragma solidity >=0.4.0 <0.6.0;
|
|
|
|
library ConcatHelper {
|
|
function concat(bytes memory a, bytes memory b)
|
|
internal pure returns (bytes memory) {
|
|
return abi.encodePacked(a, b);
|
|
}
|
|
}
|
|
|
|
******************
|
|
Advanced Questions
|
|
******************
|
|
|
|
Get return value from non-constant function from another contract
|
|
=================================================================
|
|
|
|
The key point is that the calling contract needs to know about the function it intends to call.
|
|
|
|
See `ping.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_ping.sol>`_
|
|
and `pong.sol <https://github.com/fivedogit/solidity-baby-steps/blob/master/contracts/45_pong.sol>`_.
|
|
|
|
How do I initialize a contract with only a specific amount of wei?
|
|
==================================================================
|
|
|
|
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::
|
|
|
|
pragma solidity ^0.5.0;
|
|
|
|
contract B {
|
|
constructor() public payable {}
|
|
}
|
|
|
|
contract A {
|
|
B child;
|
|
|
|
function test() public {
|
|
child = (new B).value(10)(); //construct a new B with 10 wei
|
|
}
|
|
}
|
|
|
|
More Questions?
|
|
===============
|
|
|
|
If you have more questions or your question is not answered here, please talk to us on
|
|
`gitter <https://gitter.im/ethereum/solidity>`_ or file an `issue <https://github.com/ethereum/solidity/issues>`_.
|