The MultiKeySigner is designed for high-throughput scenarios where you need to sign multiple transactions in parallel. By rotating through a set of provided keys, it helps avoid nonce conflicts that occur when multiple transactions are sent from the same key simultaneously.
When calling getPublicKey(), the signer rotates to the next key in the array. When signing transactions or delegate actions, it automatically selects the key that matches the public key specified in the transaction/action, ensuring the correct key is used for the specific operation.
const signer = new MultiKeySigner([key1, key2, key3]);
const account = new Account('account.near', provider, signer);
// These will use different keys in rotation to enable parallel execution
await Promise.all([
account.transfer({ receiverId: 'bob.near', amount: 1n }),
account.transfer({ receiverId: 'alice.near', amount: 2n }),
account.transfer({ receiverId: 'carol.near', amount: 3n }),
]);