0

I am trying to create a multi-sig proposal (eosio.msig::propose) using eosjs v20.0.0. The proposed transaction is arbitrary but in my case, I would like to propose an updateauth action.

The equivalent cleos command is:

cleos multisig propose changeowner '[{"actor": "alice", "permission": "active"}, {"actor": "bob", "permission": "active"}]' '[{"actor": "master", "permission": "owner"}]' eosio updateauth '{"account": "master", "permission": "owner", "parent": "", "auth": {"keys":[{"key":"EOS6kYgMTCh1iqpq9XGNQbEi8Q6k5GujefN9DSs55dcjVyFAq7B6b", "weight":1}],"threshold":1,"accounts":[],"waits":[]}}"}' -p alice@active

Where the master account is a multi-sig between alice and bob like

master
permissions:
    owner 2:    1 alice@active, 1 bob@active
        active 1:    1 ACTIVE_PUBLIC_KEY

My attempt to do with eosjs is following:

account = alice;
actionName = 'propose';
actionData = {
  proposer: account,
  proposal_name: 'changeowner',
  requested: [
    {
      'actor': account,
      'permission': 'active'
    },
    {
      'actor': 'bob',
      'permission': 'active'
    }
  ],
  trx: {
    expiration: '2020-04-22T16:39:15',
    ref_block_num: 0,
    ref_block_prefix: 0,
    max_net_usage_words: 0,
    max_cpu_usage_ms: 0,
    delay_sec: 0,
    context_free_actions: [],
    actions: [
      {
        account: 'eosio',
        name: 'updateauth',
        authorization: [
          {
            actor: account,
            permission: 'active'
          }
        ],
        data: {
          account: account,
          permission: 'owner',
          parent: '',
          auth: {
            keys: [
              {
                key: 'EOS6kYgMTCh1iqpq9XGNQbEi8Q6k5GujefN9DSs55dcjVyFAq7B6b',
                weight: 1
              }
            ],
            threshold: 1,
            accounts: [],
            waits: []
          }
        }
      }
    ],
    transaction_extensions: []
  }
};

try {
    const result = await api.transact({
    actions: [{
        account: 'eosio.msig',
        name: actionName,
        authorization: [{
        actor: account,
        permission: 'active',
        }],
        data: actionData,
    }]
    }, {
    blocksBehind: 3,
    expireSeconds: 30
    });

    console.log(result);
} catch (e) {
    console.log('Caught exception: ' + e);
    if (e instanceof RpcError) {
    console.log(JSON.stringify(e.json, null, 2));
    }
}

However I get the error: Caught exception: Error: Expected string containing hex digits because I am passing the action data in trx as json and not hex. Is there a way to pass in json and/or is there a way to convert my json to hex?

0

Yes, you can serialize an action using eosjs api.serializeActions()

The documentation should be located here: https://eosio.github.io/eosjs/reference/classes/api.api-1.html#serializeactions

However, I could not find any usage examples until coming across a translated Chinese version of the eosjs documentation here: https://translate.google.com/translate?hl=en&sl=zh-CN&u=http://cw.hubwiz.com/card/c/eosjs-manual/1/1/3/&prev=search

Here is the above scenario working from alice's perspective

// CREATE ACTION TO PROPOSE
let actions = [
  {
    account: 'eosio',
    name: 'updateauth',
    authorization: [
      { 
        actor: 'master',
        permission: 'owner',
      }
    ], data: {
      account: 'master',
      permission: 'owner',
      parent: '',
      auth: {
        threshold: 1,
        keys: [
          {
            key: 'EOS6kYgMTCh1iqpq9XGNQbEi8Q6k5GujefN9DSs55dcjVyFAq7B6b',
            weight: 1
          }
        ],
        accounts:[],
        waits:[]
      }
    },
  }
]

let seActions = await api.serializeActions(actions)
console.log(seActions[0].data)


// BUILD THE MULTISIG PROPOSE TRANSACTION
actionData = {
  proposer: 'alice',
  proposal_name: 'changeowner',
  requested: [
    {
      actor: 'alice',
      permission: 'active'
    },
    {
      actor: 'bob',
      permission: 'active'
    }
  ],
  trx: {
        expiration: '2020-04-22T16:39:15',
        ref_block_num: 0,
        ref_block_prefix: 0,
        max_net_usage_words: 0,
        max_cpu_usage_ms: 0,
        delay_sec: 0,
        context_free_actions: [],
        actions: [
          {
            account: 'eosio',
            name: 'updateauth',
            authorization: [
              {
                actor: 'master',
                permission: 'owner'
              }
            ],
            data: seActions[0].data
          }
        ],
        transaction_extensions: []
      }
};

// SEND THE MULTISIG PROPOSE
try {
  const result = await api.transact({
    actions: [{
      account: 'eosio.msig',
      name: 'propose',
      authorization: [{
        actor: 'alice',
        permission: 'active',
      }],
      data: actionData,
    }]
  }, {
    blocksBehind: 3,
    expireSeconds: 30,
    broadcast: true,
    sign: true
  });
  console.log(result);

} catch (e) {
  console.log('Caught exception: ' + e);
  if (e instanceof RpcError) {
    console.log(JSON.stringify(e.json, null, 2));
  }
}

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.