0

I set up vscode enviroment and launch a node with launch.json:

{
            "name": "Launch geth main",
            "type": "go",
            "request": "launch",
            "mode": "debug",
            "program": "${workspaceFolder}/src/github.com/ethereum/go-ethereum/cmd/geth/main.go",
            "env": {},
            "args": [
                "--networkid",
                123456,
                "--datadir",
                 "/root/eth/enode1/data" ,
                "--port",
                "2001", 
                "--rpc",
                "--rpcport",
                "8545",
                "--rpcapi",
                "eth,web3,admin,miner"
                ]
}

The log info in debug console of vscode after start is as below:

API server listening at: 127.0.0.1:42290
INFO [05-19|22:25:15.612] Maximum peer count                       ETH=50 LES=0 total=50
WARN [05-19|22:25:15.614] Failed to start smart card hub, disabling: dial unix /run/pcscd/pcscd.comm: connect: no such file or directory 
INFO [05-19|22:25:22.883] Starting peer-to-peer node               instance=Geth/v1.9.0-unstable/linux-amd64/go1.12.4
INFO [05-19|22:25:22.883] Allocated trie memory caches             clean=256.00MiB dirty=256.00MiB
INFO [05-19|22:25:22.883] Allocated cache and file handles         database=/root/eth/enode1/data/geth/chaindata cache=512.00MiB handles=2048
INFO [05-19|22:25:22.899] Initialised chain configuration          config="{ChainID: 7896 Homestead: 1 DAO: <nil> DAOSupport: false EIP150: 2 EIP155: 3 EIP158: 3 Byzantium: 4 Constantinople: 5  ConstantinopleFix: <nil> Engine: clique}"
INFO [05-19|22:25:22.899] Initialising Ethereum protocol           versions="[63 62]" network=123456 dbversion=6
WARN [05-19|22:25:22.938] Head state missing, repairing chain      number=40393 hash=8311c8…edee73
INFO [05-19|22:25:25.474] Rewound blockchain to past state         number=3374  hash=5f5d9f…6cd3d4
INFO [05-19|22:25:25.476] Loaded most recent local header          number=40393 hash=8311c8…edee73 td=80787 age=2d2h10m
INFO [05-19|22:25:25.476] Loaded most recent local full block      number=3374  hash=5f5d9f…6cd3d4 td=6749  age=4d5h35m
INFO [05-19|22:25:25.477] Loaded most recent local fast block      number=40393 hash=8311c8…edee73 td=80787 age=2d2h10m
INFO [05-19|22:25:25.477] Loaded local transaction journal         transactions=0 dropped=0
INFO [05-19|22:25:25.477] Regenerated local transaction journal    transactions=0 accounts=0
INFO [05-19|22:25:25.610] New local node record                    seq=6 id=ac1ba2eee1c2a6ff ip=127.0.0.1 udp=2001 tcp=2001
INFO [05-19|22:25:25.612] Started P2P networking                   self=enode://442296febed6a510feb59fff442aa320dd0474e3e22038d74501e5307fa925287acae1e2568784353b86549e608b6a357c2f09ffcfbab34a67bc1ad800b46554@127.0.0.1:2001
INFO [05-19|22:25:25.613] IPC endpoint opened                      url=/root/eth/enode1/data/geth.ipc
INFO [05-19|22:25:25.617] HTTP endpoint opened                     url=http://127.0.0.1:8545                   cors= vhosts=localhost
INFO [05-19|22:25:27.793] Mapped network port                      proto=tcp extport=2001 intport=2001 interface="UPNP IGDv1-IP1"
INFO [05-19|22:25:27.968] Mapped network port                      proto=udp extport=2001 intport=2001 interface="UPNP IGDv1-IP1"
INFO [05-19|22:25:28.065] New local node record                    seq=7 id=ac1ba2eee1c2a6ff ip=100.64.81.78 udp=2001 tcp=2001
INFO [05-19|22:26:51.996] Etherbase automatically configured       address=0x558Dfdb706847dE650dFBDC19c5295c6FE29dAB5

I encounted two problems:

First question:

When I attach the node by "geth attach http://192.168.1.253:8545", I got an error message as below:

[root@localhost bin]# geth attach http://192.168.1.253:8545
INFO [05-19|22:26:22.616] Bumping default cache on mainnet         provided=1024 updated=4096
Fatal: Failed to start the JavaScript console: api modules: Post http://192.168.1.253:8545: dial tcp 192.168.1.253:8545: connect: connection refused

but when i attach like below, it works:

[root@localhost bin]# geth attach ipc:/root/eth/enode1/data/geth.ipc
INFO [05-19|22:26:51.861] Bumping default cache on mainnet         provided=1024 updated=4096
Welcome to the Geth JavaScript console!
instance: Geth/v1.9.0-unstable/linux-amd64/go1.12.4

Meanwhile, I use postman to send json message to 192.168.1.253:8545, can not get response from geth node.

So how can I use the RPC way to attach the node, and debug code using console or postman tool?

second question:

I try to set breakpoint after I attached the node,however I found even I set a breakpoint, the code didn't stop where I input some command like "eth.accounts". How can I make the code stop where the breakpoint when I run some JSON-RPC command in attached console.

Thanks for your help.

  • IPC is the right way to attach one geth console if you are connecting to same machine.... RPC is used for connection to geth from browser or POSTMAN with the help of javascript library called web3. this link might help you : harrydenley.com/web3-rpc-api-postman You can share how are you send POSTMAN requests – logeekal May 22 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.