Skip to content

Instantly share code, notes, and snippets.

@frozeman
Last active April 15, 2020 18:28
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save frozeman/525099c084a0dfa2bf6c to your computer and use it in GitHub Desktop.
Save frozeman/525099c084a0dfa2bf6c to your computer and use it in GitHub Desktop.
web3.js API changes

TODO: update web3.js examples ?

  • uses BN instead of BigNumber

  • added websockets and new events for these providers (web3.currentProvider.on 'connect', 'end', 'error', 'timeout')

  • changed web3.eth.sendRawTransaction -> web3.eth.sendSignedTransaction

  • added web3.eth.subscription

    • web3.eth.subscription('logs', {address: '0x12', topics: [], fromBlock: ''}) allows only fromBlock, use web3.eth.getPastLogs for a specifc range of past blocks.
    • subscriptions return events like:
      • for "logs": "error", "log", "deleted/reverted"
      • for syncing: "error", "started", "processing", "ended"
      • for transaction: "error", "transaction"
  • added web3.eth.getPastLogs

  • made myContract.myEvent subscription based

    • event return values are now called returnValues (before args)
    • added a myContract.myEvent.getPastEvents(options) function
    • moved indexed parameters into the options object, of events and getPastEvents {filter: {myValue1: 23, myValue2: [3,5], ...}, fromBlock:.., toBlock:...}
  • contracts changed:

    • added: ethereum/EIPs#68
    • all addresses returned are checksum addresses
    • events moved data and topcis to raw
    • contract events return receipts with "rawLogs" and "events" property
  • add toChecksumAddress and isChecksumAddress

// packages:

  • add pkg.providers and pkg.setProvider and pkg.currentProvider to all (sub) packages

  • web3.providers are now separate pacakges

  • Providers don't have provider.isConnected() anymore.

web3._extend

  • changed to web3.extend and add pkg.extend
  • now structure can just be:
web3.extend({
   property: 'admin',
   methods: [{
      name: 'myMethod',
      call: 'eth_myCall',
      params: 3,
      inputFormatter: [null, web3.extend.formatters.inputTransactionFormatter, web3.extend.utils.fromDecimal]
      outputFormatter
   },{...}]
});

web3.personal:

  • moved to web3.eth
  • personal.listAccounts -> personal.getAccounts()

web3.net

  • moved to web3.eth

  • net.listening -> eth.net.isListening

  • net.peerCount -> eth.net.getPeerCount

  • net.version -> eth.net.getId web3.eth

  • web3.eth.contract -> web3.eth.Contract

  • web3.createBatch -> new web3.BatchRequest()

  • sendRawTransaction -> sendSignedTransaction

  • isSyncing -> subscribe('syncing')

  • eth.syncing -> isSyncing()

  • removed eth.sendIBANTransaction

  • removed eth.namereg

  • removed eth.icapNamereg

  • removed eth.iban (move to ?)

  • all eth.<properties> to eth.get<Property>()

  • property mining to eth.isMining()

    • web3.eth.iban -> web3.eth.Iban
    • eth.iban.toAddress(iban) eth.iban.toIban(address)
    • change iban.fromAddress -> Iban.toIbanInstance
    • change iban.address -> Iban.ethereumAddress

utils

  • utils -> web3.utils
  • toBigNumber -> toBN
  • fromDecimal -> numberToHex
  • toDecimal -> hexToNumberString returns now string
  • add hexToNumber
  • add hexToBytes
  • add bytesToHex
  • add isBN
  • isChecksumAddress -> checkAddressChecksum
  • sha3 autodetecs HEX strings now, no {hex: true} anymore
  • added soliditySha3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment