- Notifications
You must be signed in to change notification settings - Fork0
baby636/web3.js
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is the EthereumJavaScript APIwhich connects to theGeneric JSON-RPC spec.
You need to run a local or remoteEthereum node to use this library.
Please read thedocumentation for more.
npm install web3
yarn add web3
Use the prebuiltdist/web3.min.js
, orbuild using theweb3.js repository:
npm run build
Then includedist/web3.min.js
in your html file.This will exposeWeb3
on the window object.
Or via jsDelivr CDN:
<scriptsrc="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
UNPKG:
<scriptsrc="https://unpkg.com/web3@latest/dist/web3.min.js"></script>
// In Node.jsconstWeb3=require('web3');letweb3=newWeb3('ws://localhost:8546');console.log(web3);>{eth: ...,shh: ...,utils: ..., ...}
Additionally you can set a provider usingweb3.setProvider()
(e.g. WebsocketProvider):
web3.setProvider('ws://localhost:8546');// orweb3.setProvider(newWeb3.providers.WebsocketProvider('ws://localhost:8546'));
There you go, now you can use it:
web3.eth.getAccounts().then(console.log);
We support types within the repo itself. Please open an issue here if you find any wrong types.
You can useweb3.js
as follows:
importWeb3from'web3';constweb3=newWeb3('ws://localhost:8546');
If you are using the types in acommonjs
module, like in a Node app, you just have to enableesModuleInterop
andallowSyntheticDefaultImports
in yourtsconfig
for typesystem compatibility:
"compilerOptions":{"allowSyntheticDefaultImports":true,"esModuleInterop":true, ....
If you are using Ionic/Angular at a version >5 you may run into a build error in which modulescrypto
andstream
areundefined
a work around for this is to go into your node-modules and at/angular-cli-files/models/webpack-configs/browser.js
change thenode: false
tonode: {crypto: true, stream: true}
as mentionedhere
Another variation of this problem was an issue opned on angular-cli:angular/angular-cli#1548
Documentation can be found atReadTheDocs.
sudo apt-get updatesudo apt-get install nodejssudo apt-get install npm
Build the web3.js package:
npm run build
npmtest
Please follow theContribution Guidelines andReview Guidelines.
This project adheres to theRelease Guidelines.
- Haskell:hs-web3
- Java:web3j
- PHP:web3.php
- Purescript:purescript-web3
- Python:Web3.py
- Ruby:ethereum.rb
- Scala:web3j-scala
This project followssemver as closely as possiblefrom version 1.3.0 onwards. Earlier minor version bumpsmight have included breaking behavior changes.
About
Ethereum JavaScript API
Resources
License
Code of conduct
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Languages
- JavaScript84.8%
- TypeScript13.8%
- Shell1.1%
- Other0.3%