3

I'm trying to use https://github.com/ethereum/web3.js/blob/master/lib/solidity/coder.js to easily encode/decode my data but i'm having a hardway figuring out how to use it.

Is it available as a function of web3 directly ?

Can someone explain me how to use it ?

4
  • 2
    Sounds like an XY problem. Please ask about your actual problem. Typically, encoding and decoding is automatically handled by Contract Methods.
    – eth
    Commented Jun 28, 2016 at 23:21
  • The OP would perhaps need to decode the data in the event logs , for which there is no direct way but to use the coder.js Commented Jun 29, 2016 at 5:04
  • I'm trying to use JSON rpc api , without making transaction with web3. so encoding isn't done anywhere sadly :( but if you know how to encode the argument and decode the data " automatically " without web3, but only the coder module , i'm all hears. I'm trying to avoid using javascript as much as possible to make / receive calls. Only encoding / decoding would be find thought.
    – solinooby
    Commented Jun 29, 2016 at 7:13
  • Which language are you using? Did you check if there is a library that can help you?
    – Ismael
    Commented Jun 29, 2016 at 7:39

1 Answer 1

4

You could do it, For which you would need to use node.js and browserify module to build the coder.js.

  1. Please follow the instruction on how to download and install node.js and module browserify.
  2. Download web3.js-0.16.0 from github ( which ever latest version )
  3. Considering your node.js and browserify is installed,create a file (lets call it index-coder.js) in the root directory of web3.js-0.16.0, with content
var coder = require('./lib/solidity/coder');
        // NOTE NOTE the path in the require
        // dont override global variable
        if (typeof window !== 'undefined' && typeof window.coder === 'undefined') {
            window.coder = coder;
        }
        module.exports = coder;
  1. browserify index-coder.js -o bundled.js command in the root of the web3.js-0.16.0, directory where the index-coder.js was created. Step 4: You will have a file named bundled.js which contains the coder code.

I have the github location https://github.com/The-Neo-Noir/BloodbankEventDapp/tree/master/js/bundled.js created with an example of how to use the coder.js ( bundled.js) as well.

2
  • When i use var SolidityCoder = require("web3/lib/solidity/coder.js"); i receive this error : Error: Cannot find module 'web3/lib/solidity/coder.js' Do you know what is the reason?, Thanks.
    – Questioner
    Commented May 10, 2018 at 0:29
  • @sas You need a "./" at the beginning, which it should be require('./web3/lib/solidity/coder')
    – Richard Fu
    Commented Jun 20, 2018 at 3:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.