Ming-der Wang, twitter @mingderwang
ming@Log4Analytics.com
王銘德
如果你做了你的客製化 "tokens" (代幣)
例如:
Use TEST-NET to Mine and Test Your Smart Contracts
Use Official Ethereum Wallet (Mist) to Run Your TEST-NET as Your Dev Env
Use Gist to Save Your Code
Use Solidity Real Time Compiler If You Want
Use eth or geth CLI When You Are An Expert
then, Deploy Your Code On Ethereum Main Network!
Ethereum Wallet
Solidity Realtime Compiler
contract mortal {
address owner;
function mortal() {
owner = msg.sender; }
/* Function to recover the funds on the contract */
function kill() {
if (msg.sender == owner)
selfdestruct(owner); }
}
contract helloworld is mortal {
/* helloworld inherits all behaviors of mortal, such as function mortal(), kill() and owner */
string storeData;
function set(string x) {
storeData = x; }
function get() constant returns (string data) {
return storeData; }
}
bool
int8, int16, int24 ... int256
uint8, uint16, ... uint256
uint and int are aliases for uint256 and int256,
address
string
bytes1, bytes2, bytes3, ..., bytes32.
byte is an alias for bytes1
struct Funder { address addr; uint amount; }
int8 y = -3; uint x = uint(y);
uint20 x = 0x123; var y = x;
// y will be unit20 too
uint32 a = 0x12345678; uint16 b = uint16(a); // b will be 0x5678 now
contract MyToken { /* This creates an array with all balances */
mapping (address => uint256) public balanceOf;
function MyToken() {
balanceOf[msg.sender] = 21000000; }
}
contract C { function f(uint len) { uint[] memory a = new uint[](7); bytes memory b = new bytes(len);// memory // Here we have a.length == 7 and b.length == len a[6] = 8; } }
Variables of type bytes and string are special arrays. A bytes is similar to byte[], but it is packed tightly in calldata. string is equal to bytes but does not allow length or index access (for now).
contract Sharer { function sendHalf(address addr) returns (uint balance) { if (!addr.send(msg.value/2)) throw; // also reverts the transfer to Sharer return this.balance; } }
To create a new contract, such as "Greeter"
https://www.ethereum.org/token#the-code
To use "MyToken" contract to send tokens
address holds a 20 byte value (size of an Ethereum address). Address types also have members, like send()
address x = 0x123; address myAddress = this; if (x.balance < 10 && myAddress.balance >= 10) x.send(10);
All contracts inherit the members of address, so it is possible to query the balance of the current contract using this.balance.
address nameReg = 0x72ba7d8e73fe8eb666ea66babc8116a41bfb10e2; nameReg.call("register", "MyName"); nameReg.call(bytes4(sha3("fun(uint256)")), a);
“calldata”, which is a non-modifyable non-persistent area where function arguments are stored. Function parameters (not return parameters) of external functions are forced to “calldata” and it behaves mostly like memory.
Every complex type, i.e. arrays and structs, has an additional annotation, the “data location”.
contract c {
uint[] x; // the data location of x is storage
// the data location of memoryArray is memory
function f(uint[] memoryArray) {
x = memoryArray; // works, copies the whole array to storage
var y = x; // works, assigns a pointer, data location of y is storage
y[7]; // fine, returns the 8th element
y.length = 2; // fine, modifies x through y
delete x; // fine, clears the array, also modifies y
y = memoryArray; // not working
delete y; // not working
g(x); // calls g, handing over a reference to x
h(x); // calls h and creates an independent, temporary copy in memory
}
function g(uint[] storage storageArray) internal {}
function h(uint[] memoryArray) {}
}
contract DeleteExample {
uint data;
uint[] dataArray;
function f() {
uint x = data;
delete x; // sets x to 0, does not affect data
delete data; // sets data to 0, does not affect x which still holds a copy
}
uint[] y = dataArray;
delete dataArray; // this sets dataArray.length to zero, but as uint[] is a complex object, also
// y is affected which is an alias to the storage object
// On the other hand: "delete y" is not valid, as assignments to local variables
// referencing storage objects can only be made from existing storage objects.
}
}
[ { "constant": false, "inputs": [], "name": "kill", "outputs": [], "type": "function" }, { "constant": false, "inputs": [ { "name": "x", "type": "string" } ], "name": "set", "outputs": [], "type": "function" }, { "constant": true, "inputs": [], "name": "get", "outputs": [ { "name": "data", "type": "string", "value": "hello CCLiang" } ], "type": "function" } ]
跟你的 Contract Address
寄給他們 Contract JSON
點擊
Contract Address
點擊
http://dapps.ethercasts.com/
Ethereum-based
Bitcoin-based
如果您喜歡這場演講內容,
你可以用 Ether 幣贊助我們
飲料, 場地, 和研究經費
Taipei Ethereum Meetup
Further Reading: https://medium.com/@ConsenSys/a-101-noob-intro-to-programming-smart-contracts-on-ethereum-695d15c1dab4#.wxbzewj7w