# 以太坊交互 ## Clients, tools, dapp browsers, wallets and other projects https://github.com/ethereum/wiki/wiki/Clients,-tools,-dapp-browsers,-wallets-and-other-projects ## account,public key, private key, keystore https://theethereum.wiki/w/index.php/Accounts,_Addresses,_Public_And_Private_Keys,_And_Tokens ## 以太坊文档整理 https://www.jianshu.com/p/3445ff08229a ## geth开启测试网 https://ethereum.stackexchange.com/questions/3514/how-to-call-a-contract-method-using-the-eth-call-json-rpc-api ## 管理api https://github.com/ethereum/go-ethereum/wiki/Management-APIs ## 一般api https://github.com/ethereum/wiki/wiki/JSON-RPC 请求示例: ``` curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"web3_clientVersion","params":[],"id":67}' http://localhost:8545 ``` curl -X POST -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method": "admin_startRPC", "params": ["0.0.0.0", 8545],"id":74}' http://localhost:8545 ## 以太坊networkid 0: Olympic, Ethereum public pre-release testnet 1: Frontier, Homestead, Metropolis, the Ethereum public main network 1: Classic, the (un)forked public Ethereum Classic main network, chain ID 61 1: Expanse, an alternative Ethereum implementation, chain ID 2 2: Morden, the public Ethereum testnet, now Ethereum Classic testnet 3: Ropsten, the public cross-client Ethereum testnet 4: Rinkeby, the public Geth PoA testnet 8: Ubiq, the public Gubiq main network with flux difficulty chain ID 8 42: Kovan, the public Parity PoA testnet 77: Sokol, the public POA Network testnet 99: Core, the public POA Network main network 100: xDai, the public MakerDAO/POA Network main network 401697: Tobalaba, the public Energy Web Foundation testnet 7762959: Musicoin, the music blockchain 61717561: Aquachain, ASIC resistant chain [Other]: Could indicate that your connected to a local development test network. ## nxt api(第三方) https://nxtwiki.org/wiki/The_Nxt_API ## event watcher https://blog.joincivil.com/interacting-with-ethereum-smart-contract-events-in-go-with-the-civil-events-crawler-7db484a78d5f ## etherscan查ETH转账信息(5 requests/second) http://api-ropsten.etherscan.io/api?module=account&action=txlist&address=0x1ffc4d9156da9a622dafac9e60afb92a77a4c185&startblock=0&endblock=99999999&sort=asc&apikey=EI8E9QTV3M22MXRUEEV9TWWK33JG99DUQC ## etherscan查token转账信息(5 requests/second) http://api-ropsten.etherscan.io/api?module=account&action=tokentx&address=0x1ffc4d9156da9a622dafac9e60afb92a77a4c185&startblock=0&endblock=999999999&sort=asc&apikey=HT713H5357WVPBNURMZGU1VAZGJ14GVNI8 ## etherscan查token转账信息 https://rinkeby.etherscan.io/apis#logs 对应的rpc接口是这个 [eth_getLogs](https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getlogs) core/types里面定义了数据结构 github issue link: https://github.com/ethereum/go-ethereum/issues/2085 ## json rpc 2.0规范 https://www.jsonrpc.org/specification ## keystore和private key的区别 https://github.com/MyEtherWallet/knowledge-base/blob/master/src/content/private-keys-passwords/difference-beween-private-key-and-keystore-file.md ## 使用rpc调用geth server http://nxtwiki.org/wiki/The_Nxt_API#Get_Account_Transactions ## jsonrpc调用示例 curl -X POST -H "Content-Type:application/json" -d '{"jsonrpc":"2.0","method":"net_version","params":[],"id":67}' http://127.0.0.1:8545 ## 生成钱包(命令行) ``` bash Shimings-Mini:~ Shiming$ geth account new INFO [08-22|11:17:46.024] Maximum peer count ETH=25 LES=0 total=25 Your new account is locked with a password. Please give a password. Do not forget this password. Passphrase: Repeat passphrase: Address: {59fcaa69241cd8ac665dae468ca444c88166ed97} ``` ## golang生成公私秘钥对 https://ethereum.stackexchange.com/questions/39900/create-ethereum-account-using-golang ``` go package main import ( "github.com/ethereum/go-ethereum/crypto" "encoding/hex" "fmt" ) // Create an account func main(){ generateEthAccount() } func generateEthAccount(){ // Create an account key, err := crypto.GenerateKey() // Get the address address := crypto.PubkeyToAddress(key.PublicKey).Hex() // 0x8ee3333cDE801ceE9471ADf23370c48b011f82a6 // Get the private key privateKey := hex.EncodeToString(key.D.Bytes()) // 05b14254a1d0c77a49eae3bdf080f926a2df17d8e2ebdf7af941ea001481e57f fmt.Printf("the key is: %s\n the err is: %s\n the address is %s\n the private key is %s\n", key,err,address,privateKey) } ``` ## infura rpc Main Ethereum Network https://mainnet.infura.io/aikxiYGH1Yoq8PVbKNB6 Test Ethereum Network (Ropsten) https://ropsten.infura.io/aikxiYGH1Yoq8PVbKNB6 ## 查询地址余额 https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getbalance 0x3d089089313e11cc78ba170e6739a3962f00149e ``` json // Request curl -X POST --data '{"jsonrpc":"2.0","method":"eth_getBalance","params":["0xc94770007dda54cF92009BFF0dE90c06F603a09f", "latest"],"id":1}' https://ropsten.infura.io/aikxiYGH1Yoq8PVbKNB6 // Result { "id":1, "jsonrpc": "2.0", "result": "0x0234c8a3397aab58" // 158972490234375000 } ``` ## abigen abigen --sol helloworld.sol --pkg main --out helloworld.go ## go和合约交互 https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts ## github @vincentserpoul 邮件沟通后推荐的书 https://github.com/miguelmota/ethereum-development-with-go-book ## 判断交易是否成功 https://ethereum.stackexchange.com/questions/6002/transaction-status/6003#6003 ## 校验以太坊地址 http://blog.luoyuanhang.com/2018/04/17/eth-basis-accounts-address-pubkey-prikey/ ## 获得geth的配置信息 ``` geth dumpconfig ``` ## 生成geth配置文件 https://ethereum.stackexchange.com/questions/29063/geth-config-file-documentation/29246#29246 ## ETH 节点搭建相关信息 ``` geth removedb --datadir data geth --syncmode=full --datadir /mnt/disk2/ethereum/mainnet --rpc --rpcapi eth,net,web3,admin,miner,debug,personal,txpool,db,shh --rpcaddr 127.0.0.1 --rpcport 8543 --port 30303(加上--rpccorsdomain *就是启动不了) rinkeby ropsten 两个不同的测试网 ``` ###### tags: `区块链` `ETH`