web3.js學習記錄:查看geth賬戶信息

html代碼如下:

<html>
    <head>
        <meta charset="utf-8">
        <title>Fist App Demo</title>
        <link rel="stylesheet" type="text/css" href="main.css">
        <script src="https://cdn.staticfile.org/jquery/2.0.0/jquery.min.js"></script>
        <script src="https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js"></script>
    </head>
    <body>
        <div class="container">
            <h1>Web3.js 0.20 Demo Dapp Demo</h1>
            <h2 id="info"></h2>
        </div>
        <script>            
            if (typeof web3 !== 'undefined') {
                web3 = new Web3(web3.currentProvider);
                console.log(1)
            } else {
            // set the provider you want from Web3.providers
            web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8121"));
            console.log(2)
            }
            console.log('web3 version',web3.version)
            // 查看賬戶信息
            web3.eth.getAccounts(console.log);
        </script>
    </body>
</html>

啓動geth:

geth --networkid "12" --rpc --rpcport "8121" --rpccorsdomain "*" --datadir node0 --port "8545" --nodiscover --ipcdisable console

火狐瀏覽器控制檯輸出:

2 																	web3_0.20.html:25:21
web3 version 1.2.6 													web3_0.20.html:27:21

(2) […]
​
0: "0x6045ff8EAeC8be1B75Fae4F7D9dD55a9838d599D"
​
1: "0x46dDAC9996Ae42e2DA25eFe460A794A1c7D69280"
​
length: 2
​
<prototype>: Array []												web3.min.js:1:459693

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章