1、web3.js API
https://github.com/ethereum/web3.js/tree/1.0
https://web3js.readthedocs.io/en/1.0/#
- Python Web3.py:https://github.com/pipermerriam/web3.py
- Haskell hs-web3- Haskell hs-web3:https://github.com/airalab/hs-web3
- Java web3j- Java web3j:https://github.com/web3j/web3j
- Scala web3j-scala:https://github.com/mslinn/web3j-scala
- Purescript purescript-web3:https://github.com/f-o-a-m/purescript-web3
- PHP web3.php:https://github.com/sc0Vu/web3.php
安裝:
npm install web3
1.創建web3實例,connect.js
1 var Web3 = require('web3');
2
3 //創建web3對象
4 var web3 = new Web3();
5 //鏈接到以太坊節點
6 var conn = web3.setProvider(new web3.providers.HttpProvider("http://localhos t:8545"));
7 console.log(conn)
運行:node connect.js 輸出true
2、賬戶相關API
var accounts = web3.eth.accounts;
console.info(accounts);
查看以太坊節點上所有可用的賬戶
nodejs node connect.js
true
Accounts {
currentProvider: [Getter/Setter],
_requestManager:
RequestManager {
provider:
HttpProvider {
host: 'http://localhost:8545',
httpAgent: [Agent],
timeout: 0,
headers: undefined,
connected: false },
providers:
{ WebsocketProvider: [Function: WebsocketProvider],
HttpProvider: [Function: HttpProvider],
IpcProvider: [Function: IpcProvider] },
subscriptions: {} },
givenProvider: null,
providers:
{ WebsocketProvider: [Function: WebsocketProvider],
HttpProvider: [Function: HttpProvider],
IpcProvider: [Function: IpcProvider] },
_provider:
HttpProvider {
host: 'http://localhost:8545',
httpAgent:
Agent {
_events: [Object],
_eventsCount: 1,
_maxListeners: undefined,
defaultPort: 80,
protocol: 'http:',
options: [Object],
requests: {},
sockets: {},
freeSockets: {},
keepAliveMsecs: 1000,
keepAlive: true,
maxSockets: Infinity,
maxFreeSockets: 256 },
timeout: 0,
headers: undefined,
connected: false },
setProvider: [Function],
_ethereumCall:
{ getId:
{ [Function: send]
method: [Method],
request: [Function: bound ],
call: 'net_version' },
getGasPrice:
{ [Function: send]
method: [Method],
request: [Function: bound ],
call: 'eth_gasPrice' },
getTransactionCount:
{ [Function: send]
method: [Method],
request: [Function: bound ],
call: 'eth_getTransactionCount' } },
wallet:
Wallet {
_accounts: [Circular],
length: 0,
defaultKeyName: 'web3js_wallet' } }