The code below is copied from the code here
describe("hello-solana", () => {
// Loading these from local files for development
//
const connection = new Connection(`http://localhost:8899`, 'confirmed');
const payer = createKeypairFromFile(require('os').homedir() + '/.config/solana/id.json');
const program = createKeypairFromFile('./program/target/so/program-keypair.json');
it("Say hello!", async () => {
// We set up our instruction first.
//
let ix = new TransactionInstruction({
keys: [
{pubkey: payer.publicKey, isSigner: true, isWritable: true}
],
programId: program.publicKey,
data: Buffer.alloc(0), // No data
});
// Now we send the transaction over RPC
//
await sendAndConfirmTransaction(
connection,
new Transaction().add(ix), // Add our instruction (you can add more than one)
[payer]
);
});
})
In creating the TransactionInstruction
, the following object was passed {pubkey: payer.publicKey, isSigner: true, isWritable: true}
setting the payer.publicKey
as the signer.
Then later on, when submitting the transaction via sendAndConfirmTransaction
, the payer
is passed again as a signer:
await sendAndConfirmTransaction(
connection,
new Transaction().add(ix), // Add our instruction (you can add more than one)
[payer]
)
Question is, why is the key that would be the signer specified twice? When constructing the transaction objects and when submitting the transaction?
Also checking the documentation of sendAndConfirmTransaction
which can be seen here the type signature for the function is as follows:
sendAndConfirmTransaction(connection: Connection, transaction: Transaction,
signers: Signer[], options?: ConfirmOptions): Promise<TransactionSignature>
I noticed that signers
is an array. Meaning multiple signers can be passed in right? If so, what does it mean to have multiple signers passed in? Is that how multi-signature features are implemented?