Smart Contracts using Solidity, Truffle, and Ethereum TestRPC, Mocha
GPL-3.0 License
Setup
truffle init
nvm install; npm install; truffle install;
bash testrpc.sh
(or manually open new terminal and copy/paste commands contained therein)
curl -X POST --data '{"jsonrpc":"2.0","method":"net_version","params":[]}' http://localhost:8545
truffle compile --compile-all; truffle migrate --reset --network development;
truffle test
or npm run test
Debugging
set
value 10)Documentation: http://truffleframework.com/docs
Solidity
///
. shown when user is asked to confirm a transaction.payable
- keyword required at start of function for function to receive Etherkeccak256
- Ethereum hashing function (SHA-3)internal
- can only be called from contract itself (or derived contracts)memory
(not persisting) - i.e. default for function parametersstorage
(state variables) - i.e. default for local variablescallData
(immutable, non-persistent, behaves like memory) - i.e. storage of function arguments and external functionsstorage
, memory
, or state variable creates independent copyComplexDataStorage.sol
T[k]
T[]
uint[][5]
mapping(_KeyType => _ValueType).
virtually initialised wherekeccak256
hash is used to lookup the Value_KeyType
and return_ValueType
(which may also be a Mapping)a += 1
delete a
is same as a = 0
for a
of integer type)uint160
can also be converted to address
var
is not possible for function parameters or return parametersBlockchain
0
) creates a New Contract whose addressgas_price * gas
to limit the amount of work required. Gasmsg.sender
and msg.value
so Calling Contract may dynamically loadselfdestruct
operationdelegatecall
or callcode
) where remaining Ether stored at address is sent toMicropayment Channels
About
Example
TODO - Micropayments
Links
References:
Other
Forums
TODO