eg: the params in js code below,how to convert to one bytes

var min=100;
var max=100000000000;
var price=1000000000000000000000000000;
var name="john";

in solidity code below,how to get original data from bytes

function test(bytes _data)public{
uint min=...
uint max=...
string name=...

There's a way to do it..

You can use ethereumjs-abi in the client side to encode your message

  const abi = require('ethereumjs-abi');

  const params = [

  const message = `0x${abi.simpleEncode('parser(uint256,address,string)', ...params).toString('hex')}`;

  console.log(`Message: ${message}`);

  const res = await recipient.methods.test(message)
    from: accounts[0],

For the EVM side you can leverage on Poor man's decodeABI trick. In the article they use call opcode but if you use delegatecall instead you will preserve msg.sender.

contract ParserDemo {
  uint public min;
  address public who;
  string public message;
  event Parsed(uint _min, address _who, string _message);
  event Data(bytes _message);
  function test(bytes data) public {
    address a = this;
    assembly {
      if iszero(delegatecall(gas, a, add(data, 32), mload(data), 0, 0)) {
          revert(0, 0)
  function parser(uint _min, address _who, string _message) public {
    min = _min;
    who = _who;
    message = _message;
    emit Parsed(_min, _who, _message);


An important difference with your question is the message has embedded the signature of the parser() function.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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