Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromweb3/web3.js

Ethereum JavaScript API

License

NotificationsYou must be signed in to change notification settings

baby636/web3.js

 
 

Repository files navigation

web3.js

web3.js - Ethereum JavaScript API

GitterStackExchangeNPM Package VersionNPM Package DownloadsBuild StatusDev Dependency StatusCoverage StatusLernaNetlify Status

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.

Installation

Node

npm install web3

Yarn

yarn add web3

In the Browser

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>

Usage

// 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);

Usage with TypeScript

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,    ....

Trouble shooting and known issues.

Web3 and Angular

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

Documentation can be found atReadTheDocs.

Building

Requirements

sudo apt-get updatesudo apt-get install nodejssudo apt-get install npm

Building (webpack)

Build the web3.js package:

npm run build

Testing (mocha)

npmtest

Contributing

Please follow theContribution Guidelines andReview Guidelines.

This project adheres to theRelease Guidelines.

Community

Similar libraries in other languages

Semantic versioning

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

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript84.8%
  • TypeScript13.8%
  • Shell1.1%
  • Other0.3%

[8]ページ先頭

©2009-2025 Movatter.jp