---
tags: Blockchain, Javascript
---
Blockchain
===
<iframe src="//jsfiddle.net/lursun914013/mjoyr6x0/8/embedded/result/" style="display:none" ></iframe>
# Ethereum
## solidity
* testing: Truffle
* IDE:https://remix.ethereum.org/
* Code 儲存在LocalStorage
* 更新變化快
## web3
1. 0.20.7+
* [Metamask](https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn) 帶壞大家,幾乎所有 eth base 的 dapp 都使用 0.20.7+ 的用法。
3. 1.0.0-beta.55+
* 遲遲不進入 release 不知道在拖延什麼
## ethers.js
文欓:https://docs.ethers.io/ethers.js/html/
`pragma experimental ABIEncoderV2;` Encode,Decode 支援
最好有web3, ethereumjs-(tx|wallet|utils) 之基礎,用起來較得心應手。
特色:
* Wallet,Provider,Contract解偶,使用依賴注入,開發更容易。
* 支持HD錢包處理。
* 支持ENS。
* Provider可與web3連結。
* 支持Human-Readable ABI。
功能:
* Wallet
* Signer
* Provider
* Contract
* ContractFactory
部署所需
* Utils
## ethereumjs-tx
* 僅用於構成交易。
## ethereumjs-wallet
* 產生私鑰、地址、簽名等。
## ethereumjs-util
* keccak256
* ecrecover
## ethereumjs-vm
* remix 實現核心
# Bitcoin
精通比特幣(pdf):https://bitcoinbook.info/translations-of-mastering-bitcoin/
## bitcoinjs-lib
```javascript=
let network, script;
// LITECOIN
network = {
messagePrefix: '\x19Litecoin Signed Message:\n',
bip32: { // HD Wallet
public: 0x019da462,
private: 0x019d9cfe
},
pubKeyHash: 0x30,
scriptHash: 0x32,
wif: 0xb0
};
// keypair
const keyPair = bitcoinlib.ECPair.fromPrivateKey(Buffer.from(privateKeyHex, 'hex'), { network: network })
// segwit
const p2wpkh = bitcoinlib.payments.p2wpkh({ pubkey: keyPair.publicKey, network: network })
const p2sh = bitcoinlib.payments.p2sh({ redeem: p2wpkh, network: network });
script = p2sh.redeem.output; // build tx need
const address = p2sh.address // segwit address
// legacy
const p2pkh = bitcoinlib.payments.p2pkh({ pubkey: keyPair.publicKey, network: network })
const address = p2pkh.address // segwit address
// tx
let tb = new bitcoinlib.TransactionBuilder(network);
// input
tb.addInput(utxo1.txid, utxo1.index);
tb.addInput(utxo2.txid, utxo2.index);
tb.addInput(utxo3.txid, utxo3.index);
// output
tb.addOutput(address1, amount1_satoshi);
tb.addOutput(address2, amount2_satoshi);
// sign
tb.sign(0, keyPair, script, null, script && utxo1.value);
tb.sign(1, keyPair, script, null, script && utxo2.value);
tb.sign(2, keyPair, script, null, script && utxo3.value);
// build
const tx = tb.buildIncomplete();
const txstring = tx.toHex(); // send to node
```
## netwrok
<table>
<tr><td>Coin </td><td>EXT_COIN_TYPE </td><td>mainnet EXT_SECRET_KEY</td><td>mainnet EXT_PUBLIC_KEY</td><td>testnet EXT_SECRET_KEY</td><td>testnet EXT_PUBLIC_KEY</td><td>Source Code</td></tr>
<tr><td>BTC </td><td> 0x80000000 </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/bitcoin/bitcoin/blob/master/src/chainparams.cpp</td></tr>
<tr><td>LTC </td><td> 0x80000002 </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/litecoin-project/litecoin/blob/master-0.10/src/chainparams.cpp</td></tr>
<tr><td>LTC </td><td> 0x80000002 </td><td> 0x019d9cfe/Ltpv </td><td> 0x019da462/Ltub </td><td> 0x0436ef7d/ttpv </td><td> 0x0436f6e1/ttub </td><td> https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/src/BIP32.php</td></tr>
<tr><td>DOGE </td><td> 0x80000003 </td><td> 0x0488E1F4/xqRp </td><td> 0x0488C42E/xq71 </td><td> 0x043575A4/tpi7 </td><td> 0x0435D1DF/tqiQ </td><td> https://github.com/dogecoin/dogecoin/blob/master/src/chainparams.cpp</td></tr>
<tr><td>DOGE </td><td> 0x80000003 </td><td> 0x02fac398/dgpv </td><td> 0x02facafd/dgub </td><td> 0x0432a243/tgpv </td><td> 0x0432a9a8/tgub </td><td> https://github.com/Bit-Wasp/bitcoin-lib-php/blob/master/src/BIP32.php</td></tr>
<tr><td>DASH </td><td> 0x80000005 </td><td> 0x02FE52CC/drkp </td><td> 0x02FE52F8/drkv </td><td> 0x3A805837/DRKP </td><td> 0x3A8061A0/DRKV </td><td> https://github.com/dashpay/dash/blob/master/src/chainparams.cpp</td></tr>
<tr><td>NMC </td><td> 0x80000007 </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/domob1812/namecore/blob/master/src/chainparams.cpp</td></tr>
<tr><td>BLK </td><td> 0x8000000A </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/rat4/blackcoin/blob/master/src/chainparams.cpp</td></tr>
<tr><td>VIA </td><td> 0x8000000E </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/viacoin/viacoin/blob/master/src/chainparams.cpp</td></tr>
<tr><td>DGC </td><td> 0x80000012 </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/digibyte/digibyte/blob/master/src/chainparams.cpp </td></tr>
<tr><td>DGB </td><td> 0x80000014 </td><td> 0x0488ADE4/xprv </td><td> 0x0488B21E/xpub </td><td> 0x04358394/tprv </td><td> 0x043587CF/tpub </td><td> https://github.com/digibyte/digibyte/blob/master/src/chainparams.cpp</td></tr>
</table>
# EOS
## 錢包Scatter
* chrome store: [Scatter](https://chrome.google.com/webstore/detail/scatter/ammjpmhgckkpcamddpolhchgomcojkle)
## dev4eos
* https://dev4eos.com/#/