5

I am trying to create a JS code to be able to vote using proxy account that has been given democracy permissions to stash account, so I would be able to vote using just my mobile phone instead of accessing my home setup for voting using just terminal.

Substrate Extrinsics Docs instructs following proxy(real: AccountId32, force_proxy_type: Option, call: Call), so we need to make a proxy call with address of stash account, type of proxy call and call in encoded format like 0x0500306721211d5404bd9da88e0204360a1a9ab8b87c66c1bc2fcdd37f3c2222cc200f00a0be1c448399.
My struggle is, how do I get voting data this call data in encoded format? How do I use these imaginary keys to sign my vote?

const PROXY = {
               address: '5D7m1JT5QR6Pg1z4LXZPTNZqiFVzUX9NbAndeZvVzrjUCpNe',
               key: 'expose circle crack addict nasty horny men write sugar cloth sound orbit',
               type: 'Governance'
               };
const STASH = {
               address: '5Dhf5LvBWcvioXuLeGzW1xLaEKTfFmUmnE2ZC5RLKaJu2K8M',
               key: 'tank barrel crack addict nasty horny men write sugar unfold hood expect depend'
               };

       
function proxyVoting(address, type, ref_index, vote) { 
  api.tx.proxy.proxy(address, type, (call)=>{
    api.tx.democracy.vote(ref_index, vote);
  });
}
proxyVoting(STASH.address, PROXY.type, 183, true);
Error: createType(Call):: Call: failed decoding proxy.proxy:: Struct: failed on args: {"real":"AccountId32","force_proxy_type":"Option<KusamaRuntimeProxyType>","call":"Call"}:: Struct: failed on call: Call:: Call: Cannot decode value '(call)=>{
    api.tx.democracy.vote(ref_index, vote);
  }' of type function

2 Answers 2

5

To wrap something in a proxy, just pass the api.tx.<module>.<method>(...) as-is.

In code it would be -

function proxyVoting(address, type, ref_index, vote) { 
  return api.tx.proxy.proxy(
    address,
    'Governance',
    api.tx.democracy.vote(ref_index, vote)
  );
}

The same applies everywhere you need to pass a Call e.g. batch transactions, sudo, etc.

3
  • Thank you for the batch reference here, that helps.
    – Barto
    Mar 28, 2022 at 17:08
  • 1
    Actually it's return api.tx.proxy.proxy(address, "Governance", api.tx.democracy.vote(ref_index, vote)); Apr 29, 2022 at 5:56
  • Thank you adjusted. (Copied from above, so didn't check properly)
    – Jaco
    May 10, 2022 at 5:59
0

A bit more comprehensive example for people struggling with this one:

voting = {
  "stash":"publickey of stash wallet here",
  "proxy":"secret key or pass phrase here of proxy account that has Governance right to control the stash address",
  "amount":"1 000 000 000 000",
}

let stashAccount = voting.stash;
let voteAccount = keyring.addFromUri(voting.proxy);
let balance = voting.amount;
let ref_index = 195;

let vote = {
        Standard: {
            vote: {
                aye: true,
                conviction: 'None',
            },
            balance: balance,
        }
    };

const voting = await api.tx.proxy
        .proxy(
            stashAccount,
            'Governance',
            api.tx.democracy
            .vote(
                ref_index, vote
            ),
        )
        .signAndSend(voteAccount, (result) => {
            console.log(`Status: ${result.status}`);
     });

Your Answer

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

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