2017年9月16日 星期六
炒幣須知金融術語
- limit - 一般的買賣,自己設定買價賣假,match 到就成交
- market - 以現在市場價買入賣出
- stop - 市場價格到了某一個點之後,以市場價賣出一定數量的幣
- stop limit - 市場價格到了某一個點之後,以自己設定的買賣價開始買賣幣
- trailing stop - 跌到現在價格 -N 後,下 -N Stop Order,如果市場價格漲了,stop order 也跟著變高,以市場價賣出一定數量的幣。用來保護獲利。
- fill or kill - 下一個 limit order,沒有馬上成交就 cancel
bitfinex scaled order - 一次在一個 range 內下一堆 limit orders
2017年9月14日 星期四
用 screen 在 server 執行程序
screen 可以讓程序在背景跑,不會因為斷線而結束
https://blog.gtwang.org/linux/screen-command-examples-to-manage-linux-terminals/
https://blog.gtwang.org/linux/screen-command-examples-to-manage-linux-terminals/
2017年9月6日 星期三
bitcoin address validation
第一時間會想到用正規表示來驗證
正式 chain 的 regex
```
\A[13][a-km-zA-HJ-NP-Z1-9]{25,34}\z
```
Test net 的 regex
```
\A[2mn][1-9A-HJ-NP-Za-km-z]{26,35}\z
```
但是這樣只檢查表面 (可以通過大部分的檢查),沒有檢查算法,所以更嚴謹的做法是要再檢查 checksum
實作概念:
https://bitcointalk.org/index.php?topic=1026.0
概念就是使用 Base58 編碼 deocde 想要檢查的 address 做檢查
from wiki:
```
Base58是用於Bitcoin中使用的一種獨特的編碼方式,主要用於產生Bitcoin的錢包地址。相比Base64,Base58不使用數字"0",字母大寫"O",字母大寫"I",和字母小寫"l",以及"+"和"/"符號。
```
也就是說只要使用 Base58 逆向 decode 回去 checksum 就可以知道是不是正確的 address
找工具:
Bitcoin Ruby 的 Gem 有提供 `valid_address?(address)` 的方法可以用
https://github.com/lian/bitcoin-ruby#library-usage
Source code 可以看:
https://github.com/lian/bitcoin-ruby/blob/master/lib/bitcoin.rb#L59
Bitcoin Ruby gem 驗證了
* version byte
* length (bytesize)
* checksum
所以如果要驗證 testnet 或是其他 network 的地址,可以先設定
```
Bitcoin.network = :testnet
```
就行
正式 chain 的 regex
```
\A[13][a-km-zA-HJ-NP-Z1-9]{25,34}\z
```
Test net 的 regex
```
\A[2mn][1-9A-HJ-NP-Za-km-z]{26,35}\z
```
但是這樣只檢查表面 (可以通過大部分的檢查),沒有檢查算法,所以更嚴謹的做法是要再檢查 checksum
實作概念:
https://bitcointalk.org/index.php?topic=1026.0
概念就是使用 Base58 編碼 deocde 想要檢查的 address 做檢查
from wiki:
```
Base58是用於Bitcoin中使用的一種獨特的編碼方式,主要用於產生Bitcoin的錢包地址。相比Base64,Base58不使用數字"0",字母大寫"O",字母大寫"I",和字母小寫"l",以及"+"和"/"符號。
```
也就是說只要使用 Base58 逆向 decode 回去 checksum 就可以知道是不是正確的 address
找工具:
Bitcoin Ruby 的 Gem 有提供 `valid_address?(address)` 的方法可以用
https://github.com/lian/bitcoin-ruby#library-usage
Source code 可以看:
https://github.com/lian/bitcoin-ruby/blob/master/lib/bitcoin.rb#L59
Bitcoin Ruby gem 驗證了
* version byte
* length (bytesize)
* checksum
所以如果要驗證 testnet 或是其他 network 的地址,可以先設定
```
Bitcoin.network = :testnet
```
就行
相較於以太坊¶
Ethereum addresses are plain 20 bytes, anything can be in them. Since it's hard to reason about them, programs represent them as 40 character long hex strings. So every 0x<40 hex character> is a valid Ethereum address.
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
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
基本上有以下功能
https://theethereum.wiki/w/index.php/ERC20_Token_Standard
基本上現在市面上看到的各種幣有很多都是基於 Ethereum 上的 ERC20 Tokens
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
訂閱:
文章 (Atom)