顯示具有 Ethereum 標籤的文章。 顯示所有文章
顯示具有 Ethereum 標籤的文章。 顯示所有文章

2018年5月6日 星期日

Mac OS 用 Geth 跑 ETH ethereum node 全節點


https://github.com/ethereum/go-ethereum/wiki/Installation-Instructions-for-Mac


brew tap ethereum/ethereum
brew install ethereum

然後跑

geth --syncmode "fast" --cache=1024

就會開始 sync 主鏈的全節點,節點會存在

database=/Users/wayne/Library/Ethereum/geth/chaindata

路徑裡,在geth 啟動時就可以看到 database 的路徑

fast 參數是 syncmode,詳細介紹: https://everyday1percent.blogspot.com/2018/05/eth-syncmode.html



如果要 sync testnet 可以這樣:

Sync testnet (Ropsten)

```
geth --testnet --syncmode "fast" --datadir /usr/local/var/ethereum-testnet-data console 2>> /usr/local/var/log/geth.testnet.log
```

開啟 API
```
geth -- testnet  -- syncmode "fast"  -- rpc  -- rpcapi db,eth,net,web3,personal,admin  -- cache=1024  -- rpcport 8545
```

開啟 console
```
geth --testnet --syncmode "fast" console 2>> /usr/local/var/log/geth.testnet.log
```


```
echo "Geth at work!"
screen -dmS geth geth --testnet --syncmode "fast" --rpc --rpcapi db,eth,net,web3,personal --cache=1024  --rpcport 8545 --rpcaddr 0.0.0.0 --rpccorsdomain "*"
```
然後
```
geth attach http://localhost:8545
```
就可以進 console


https://ethereum.stackexchange.com/questions/392/how-can-i-get-a-geth-node-to-download-the-blockchain-quickly/4210#4210

https://medium.com/@jacksonngtech/syncing-geth-to-the-ethereum-blockchain-9571666f3cfc

eth syncmode


還不是很確定,先翻譯貼過來

Full - 拿到所有資料
Fast - 差不多的意思,但不執行transaction
Light - 只拿到現在的狀態,但不能驗證


https://ethereum.stackexchange.com/questions/11297/what-is-geths-light-sync-and-why-is-it-so-fast



更好的解釋:

主要是fast 跟 full 的差別

full 可以驗證每個 state,但 fast 因為只有 process 最近的 transactions,所以不能驗證舊的 state

https://ethereum.stackexchange.com/questions/1161/what-is-geths-fast-sync-and-why-is-it-faster

https://github.com/ethereum/go-ethereum/pull/1889


2017年9月1日 星期五

在 Geth js console send ether

http://faucet.ropsten.be:3001/


miner.setEtherbase("0xe7c2be3d07217101aeced9d68400cd142acb3d2f")

personal.unlockAccount(eth.coinbase, "11111111", 300)

eth.getBalance(eth.coinbase)

eth.sendTransaction({from: eth.coinbase, to: "0x1b5b525d4c525386855144047a6cdc64628facd3", value: 500000})


https://github.com/ethereum/go-ethereum/wiki/Sending-ether

2017年8月31日 星期四

什麼是 ERC20 token

先說明 ERC-20 Token

erc20 是公認的 token interface, 定義了一個 token 應該要有哪些 functionalities,原始提案在這:https://github.com/ethereum/EIPs/issues/20

基本上有以下功能


  • totalSupply - 得知目前 token supply 的狀態
  • balanceOf - 得知特定 Account 的 Balance
  • transfer - 可以轉帳
  • approve - 授權的 Account 幫你轉帳一定額度
  • transferFrom - 從授權給你的 Account 轉帳
  • allowance - 查看授權給你的 Account 還有多少餘額可以讓你用
  • event Transfer - 轉帳發生後的 Event
  • event Approval - Triggered when approve called


https://theethereum.wiki/w/index.php/ERC20_Token_Standard



基本上現在市面上看到的各種幣有很多都是基於 Ethereum 上的 ERC20 Tokens

Deploy contract from truffle to testnet


Truffle 設定新的 network
Geth 開啟 test net
Deploy!

In geth console
```
personal.unlockAccount(eth.accounts[0])
```

```sh
truffle migrate --network ropsten
```



```
module.exports = {
  networks: {
    development: {
      host: "localhost",
      port: 8545,
      network_id: "*" // Match any network id
    },
     ropsten:  {
     network_id: 3,
     host: "localhost",
     port:  8545,
     gas:   2900000
}
  },
   rpc: {
 host: 'localhost',
 post:8080
   }
};
```


https://medium.com/@guccimanepunk/how-to-deploy-a-truffle-contract-to-ropsten-e2fb817870c1

learn truffle and solidity - pet shop - note

* Public variables have automatic getter methods
* array getters return only a single value from a given key
* this, a contract-wide variable that gets the current contract's address
* Since the array contains address types, Ethereum initializes the array with 16 empty addresses

* Types
int: –2147483648 to 2147483647
uint: 0 to 4294967295
http://solidity.readthedocs.io/en/develop/types.html


```
mapping (address => uint) public balances;
```
=>
```
function balances(address _account) returns (uint) {
    return balances[_account];
}
```

* 跟 contract 一樣名稱的 function 就是 constructor




http://truffleframework.com/tutorials/pet-shop

2017年7月26日 星期三

開發第一個智能合約 - 環境準備



首先安裝框架
http://truffleframework.com/docs/getting_started/client



測試環境
https://github.com/ethereumjs/testrpc



package:
https://www.ethpm.com/registry