Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add extend method and tests #229

Merged
merged 4 commits into from
Jun 8, 2015
Merged

add extend method and tests #229

merged 4 commits into from
Jun 8, 2015

Conversation

frozeman
Copy link
Contributor

@frozeman frozeman commented Jun 4, 2015

adding an extend method, which allows to extend web3.js with additional RPC endpoints:

web3.extend({
  property: 'admin',
  methods: [new web3.extend.Method({
       name: 'getBalance',
       call: 'eth_getBalance',
       params: 2,
       inputFormatter: [web3.extend.utils.toAddress, web3.extend.formatters.inputDefaultBlockNumberFormatter],
       outputFormatter: web3.extend.formatters.outputBigNumberFormatter
  })],
  properties: [new web3.extend.Property({
        name: 'gasPrice',
        getter: 'eth_gasPrice',
        outputFormatter: web3.extend.formatters.outputBigNumberFormatter
  })]
})

// Will give you
web3.admin.getBalance(address, cb);
web3.admin.gasPrice;
web3.admin.getGasPrice(cb);

You can even leave the property: 'admin' property out to add functionality to the web3 object itself.

@frozeman frozeman added the Enhancement Includes improvements or optimizations label Jun 4, 2015
@frozeman frozeman self-assigned this Jun 4, 2015
@coveralls
Copy link

Coverage Status

Coverage increased (+0.06%) to 94.54% when pulling 733e19e on extendWeb3 into 61f1ba6 on develop.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.05%) to 94.53% when pulling d14c706 on extendWeb3 into 61f1ba6 on develop.

@debris
Copy link
Contributor

debris commented Jun 7, 2015

As I told you, I would prefer it to be more modular, but since it's not a lot of code let's leave it as you propose 👍 Also I would prefer to call it _extend, cause method, property, utils and formatters are a part of private api and I would not like people to use them, cause they may change in future.

frozeman added a commit that referenced this pull request Jun 8, 2015
add extend method and tests
@frozeman frozeman merged commit fe703f5 into develop Jun 8, 2015
@frozeman frozeman deleted the extendWeb3 branch June 29, 2015 10:56
@Anemy Anemy mentioned this pull request Nov 18, 2017
@stvenyin
Copy link

stvenyin commented Sep 6, 2018

OK,See..

@frozeman
Copy link
Contributor Author

frozeman commented Sep 6, 2018

Just as reference in the #1.0 version extend is exposed as follows: https://web3js.readthedocs.io/en/1.0/web3.html#extend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Includes improvements or optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants