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?