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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值