# Geth 入门---命令行操作

By [fanly](https://paragraph.com/@yemeishu) · 2022-07-17

---

启动第一个节点
-------

    geth --datadir data0 --dev console
    
    coinbase: 0x1fcc9699301f2d79c064430a5d44ccd61e8c20de
    at block: 0 (Thu Jan 01 1970 08:00:00 GMT+0800 (CST))
    

获取节点实例

    admin.nodeInfo.enode
    
    "enode://8ddd204baf8cedeb2451d9b0ad6abb09fa24319411fb0a5c164c8da6a5fea8b2f0c8d6a2cdbfc74413519ad1441fa7703d349a13b12a91aae6c956e95000db73@127.0.0.1:0"
    

查看账户，默认分配了一个开发者账户 `eth.accounts`

    ["0x1fcc9699301f2d79c064430a5d44ccd61e8c20de"]
    

这个也就是上文显示的 coinbase。

创建账户
----

创建账户，「mumu」是新账户的密码 `personal.newAccount('mumu')`

    > personal.newAccount('1q2w3e4r5t6y1')
    INFO [05-26|16:37:17.083] Your new key was generated               address=0xf3D69d972E88aF6C2eCB7E64F94f737aa5355Dd5
    WARN [05-26|16:37:17.085] Please backup your key file!             path=/Users/yemeishu/Documents/code/web3/data0/keystore/UTC--2022-05-26T08-37-16.921851000Z--f3d69d972e88af6c2ecb7e64f94f737aa5355dd5
    WARN [05-26|16:37:17.085] Please remember your password! 
    "0xf3d69d972e88af6c2ecb7e64f94f737aa5355dd5"
    

查看是否创建成功：

    > eth.accounts
    ["0x1fcc9699301f2d79c064430a5d44ccd61e8c20de", "0xf3d69d972e88af6c2ecb7e64f94f737aa5355dd5"]
    > 
    

查看两个账号余额：

    > eth.getBalance(eth.accounts[0])
    1.15792089237316195423570985008687907853269984665640564039457584007913129639927e+77
    > eth.getBalance(eth.accounts[1])
    0
    

转账
--

这时候我们从 coinbase 账号转移 1 个以太币给新账户：

    eth.sendTransaction({from: eth.accounts[0], to: eth.accounts[1], value: web3.toWei(1,'ether')})
    

这个挺好理解的，就是执行一次交易 (transaction)，这过程需要一段时间执行：

![](https://storage.googleapis.com/papyrus_images/456129d60e698b60a078db429f30e560d8a2cccb676e697367ec0bd7fb8e5e8c.jpg)

转账成功：

![](https://storage.googleapis.com/papyrus_images/ac0ffade35475803c6bb5d5d70aa992ec32c12dd975679c73f7d7bef453bfdd1.jpg)

解锁账户 在部署合约前需要先解锁账户

    personal.unlockAccount(eth.accounts[1])
    

输入密码，解锁成功。

![](https://storage.googleapis.com/papyrus_images/765bcf013b178380e10189f0467040281dd776960825e06f43278de5bff05e1d.jpg)

---

*Originally published on [fanly](https://paragraph.com/@yemeishu/geth)*
