Skip to content

Instantly share code, notes, and snippets.

@ferni
Created December 17, 2016 14:19
Show Gist options
  • Save ferni/413e56354b34731793ed0ecd2f6cfb70 to your computer and use it in GitHub Desktop.
Save ferni/413e56354b34731793ed0ecd2f6cfb70 to your computer and use it in GitHub Desktop.
Fixes web3.sha3 leading '0x' compatibility issue between <= 0.15 and >= 0.16 versions
var Web3 = require('web3');
var web3 = new Web3();
function fixSha3(web3) {
var original = web3.sha3;
web3.sha3 = function() {
var result = original.apply(this, arguments);
if (result[1] !== 'x') {
return '0x' + result;
}
return result;
}
return web3;
}
console.log(web3.sha3('asdf'));
fixSha3(web3);
console.log(web3.sha3('asdf'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment