How to use the web3/lib/solidity/coder.encodeParams function in web3

To help you get started, we’ve selected a few web3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ethers-io / ethers.js / tests / make-tests / make-contract-events.js View on Github external
if (baseType.substring(0, 5) === 'bytes') {
                                    return input;
                                }

                                if (typeof(input) === 'boolean') {
                                    return input;
                                }

                                return web3.toBigNumber(input);
                            }

                            var web3Value = dump(param.value);

                            // The web3 coder has lots of bugs, but it does fine as long as there
                            // is only one type and nothing is dynamic
                            var encoded = web3Coder.encodeParams([ compute ], [ web3Value ]);
                            normalizedValues.push(keccak256(Buffer.from(encoded, 'hex')));

                        } else {
                            throw new Error('unknown hashed type');
                        }
                    } else {
                        hashed.push(false);
                        normalizedValues.push(param.value);
                    }
                    values.push(param.value);
                });
github 3box / muport-core-js / src / ethereum-utils.js View on Github external
const encodeMethodCall = (methodName, args) => {
  const methodAbi = RevokeAndPublishAbi.filter(obj => obj.name === methodName)[0]
  const types = methodAbi.inputs.map(o => o.type)
  const fullName = methodName + '(' + types.join() + ')'
  const signature = CryptoJS.SHA3(fullName, { outputLength: 256 }).toString(CryptoJS.enc.Hex).slice(0, 8)

  return '0x' + signature + coder.encodeParams(types, args)
}