1

I would like to extract the validator that a given nominator is bonding? Is this possible given the extrinsic or should it be done some other way?

Here is my code:

const { ApiPromise, WsProvider } = require('@polkadot/api');

async function main() {
    // Initialise the provider to connect to the local node
    const provider = new WsProvider('wss://rpc.polkadot.io');

    // Create the API and wait until ready
    const api = await ApiPromise.create({ provider });

    const blockNumber = 11833484; 

    // returns Hash
    const blockHash = await api.rpc.chain.getBlockHash(blockNumber);
    // returns SignedBlock
    const signedBlock = await api.rpc.chain.getBlock(blockHash);

    const apiAt = await api.at(signedBlock.block.header.hash);
    const allRecords = await apiAt.query.system.events();


    const bondingEvents = allRecords.filter(ev => ev.event.method == 'Bonded');
    const bondingExtrinsics = bondingEvents
        .map(ev => 
            signedBlock.block.extrinsics.at(ev.phase.asApplyExtrinsic)
        );

    console.log(bondingExtrinsics[0].toHuman());
}


main().catch((error) => {
    console.error(error);
    process.exit(-1);
});

output:

{
  isSigned: true,
  method: {
    args: { max_additional: '13,428,193,000,000' },
    method: 'bondExtra',
    section: 'staking'
  },
  era: { MortalEra: { period: '64', phase: '7' } },
  nonce: '283',
  signature: '0x04aebb51e2b2b1947e3e344537caa45cad9caa170808d8ed2f448ef4e0433b69820e5f60b35065ed7c7adc0ecb88d03b9e1fdf46e6873b8f9263738dbc874080',
  signer: { Id: '15V25oBZGu7wAfV7LPP8YBwaWRgBAyfiVUtVywGHAcDAw9cD' },
  tip: '0'
}

The amount bonded and the account which is bonding are both clearly visible in the output. How, then, should I go about retrieving the validator which is being bonded to?

1 Answer 1

0

In this case, the user is not changing their nominations, but simply bonding more funds.

For this, you will need to query the nominations of the user, which can be done with something like:

let result = (await substrate.query.staking.nominators("15V25oBZGu7wAfV7LPP8YBwaWRgBAyfiVUtVywGHAcDAw9cD")).unwrap();

result.targets.toHuman()
[
  "13s9RrQSFbnp2TneY7nkdLmGc3ijBw12YQct8pc8km36Z9hg",
  "126RwaHn4MDekLWfUYfiqcVbiQHapwDSAT9vZZS15HLqfDJh",
  "15qomv8YFTpHrbiJKicP4oXfxRDyG4XEHZH7jdfJScnw2xnV",
  "123kFHVth2udmM79sn3RPQ81HukrQWCxA1vmTWkGHSvkR4k1",
  "167ShbHu769mP5jbtt7AHayJhzEied6s8M5kN5nBSAQewnRz",
  "13AxLFBLRACDWzjqEQn3YhHH2iErmyj3kC1HivYiSahkN2Fh",
  "131RTKxEkG6o1HZRRmETxj8ywpSsoF8KgoQp6twnMUf7W4Nu",
  "14aWupX88TM23UCmUTx69S9x9r7JNTLUZ4oprbdwy2s2xWyJ",
  "153RzmMmQ2ueHgD71nRcfcs96VKhFRPYkW2h1qw18Bn1Jkrv",
  "15dMdEYxCM9EWtbBdDf1vEvRV3se1tpvvxitFCURXV2jWArs",
  "1xzAes4aS1EK2hDBcuK3ZSrwvH4Hn4b5hs6aKrsoC8scLGK",
  "16aXLhFh9mZoyW5emqZM6fJWTqbWENGrJkAoGwtR1S8XoFwY",
  "13fj8s7NEamwDw2PmHVJ9acHApBMCLuRX2exbnovkxNa2fQV",
  "15ovsfcNsVc666r55fi4D6qiXpgP23ReRmPZL6Ss1THJ4rf2",
  "1KPeYhx2k2D4Fy7iw9CSykbTYN1UbtYxHpBceL85xQhAJdo",
  "16XwmL8Kh4fxXa4TyEAjaJRr1JLevnQsZ2GVF68ND9SqQWY4"
]
2
  • When they bond more funds are those funds split evenly between their nominations? How can I derive the total amount they have bonded to their nominations?
    – Teo
    Sep 22, 2022 at 14:34
  • 1
    I think you need to look more into the Phragmen election process used in Polkadot. Basically, we have an algorithm which automatically distributes your funds based on a set of criteria, one of which is make sure validators have as close to even amount of stake across them all. This means, you do not control how much each validator gets, but an algorithm will.
    – Shawn Tabrizi
    Sep 22, 2022 at 15:15

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.