0

let wallet = Keypair.fromSecretKey(Uint8Array.from(key));
console.log("wallet", await wallet.publicKey.toBase58());
// 3 keypairs
const pk1 = Keypair.fromSecretKey(Uint8Array.from(key1));
console.log("wallet 1", pk1.publicKey.toBase58());
const pk2 = Keypair.fromSecretKey(Uint8Array.from(key2));
console.log("wallet 2", pk2.publicKey.toBase58());
const pk3 = Keypair.fromSecretKey(Uint8Array.from(key3));
console.log("wallet 3", pk3.publicKey.toBase58());

const multisigKey = Keypair.generate();
console.log("mullll", multisigKey.publicKey.toBase58());

const hi = await createMultisig(
  connection,
  pk1,
  [pk1.publicKey, pk2.publicKey, pk3.publicKey],
  2,
  multisigKey
);
console.log("multi sig", hi.toBase58());

const transaction = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: wallet.publicKey,
    toPubkey: hi,
    lamports: 15651157,
  })
);

// Sign and send the transaction
const signature = await sendAndConfirmTransaction(connection, transaction, [
  wallet,
]);
console.log(`Transaction ${signature} confirmed`);

const transaction2 = new Transaction().add(
  SystemProgram.transfer({
    fromPubkey: hi,
    toPubkey: wallet.publicKey,
    lamports: 15655,
  })
);

transaction2.recentBlockhash = (
  await connection.getLatestBlockhash()
).blockhash;

transaction2.feePayer = pk2.publicKey;
transaction2.partialSign([pk1, pk3]);
transaction2.sign(pk2);
console.log(await transaction2.verifySignatures());
// Sign and send the transaction
const sign = await connection.sendRawTransaction(transaction2.serialize());
await connection.confirmTransaction(sign, "confirmed");
// const sign = await sendAndConfirmTransaction(connection, transaction, [
//   pk1,
//   pk2,
// ]);
console.log(`Transaction ${sign} confirmed`);

and this is what i get in my console

wallet 5oMMY9cDEp36zWqYqoKYoW2wY1eheWk5wvS8Gb636BKC
wallet 1 8Mh5T8mH43gEoAaAo27mEiB6g7w4cEmP8Gaao1iUjPnA
wallet 2 AGdXuBtXLZ4nT7JHsTSTJc4a8sqDUH9JGLSpu5XRwFx1
wallet 3 4XrYJtuXa75f4wVJbGExSwCDuLJMJU46yEkgc9PNeRR5
mullll A9gqQzKXSzEZmjA18dKrni6NXEriiZSo1x2oh6dz5yn3
multi sig A9gqQzKXSzEZmjA18dKrni6NXEriiZSo1x2oh6dz5yn3
Transaction 2qhjutP2CTrX61BtujJya7RiKanwJWjyBuFpXCU52KqCV85WjP3o9d6Nugex8doQRErMTZcy83rzduT8NSHg5FdJ confirmed
/home/dev-ice/bitoku/test/node_modules/@solana/web3.js/lib/index.cjs.js:1879
      throw new Error(`unknown signer: ${pubkey.toString()}`);
            ^

Error: unknown signer: 8Mh5T8mH43gEoAaAo27mEiB6g7w4cEmP8Gaao1iUjPnA
    at Transaction._addSignature (/home/dev-ice/bitoku/test/node_modules/@solana/web3.js/lib/index.cjs.js:1879:13)
    at /home/dev-ice/bitoku/test/node_modules/@solana/web3.js/lib/index.cjs.js:1853:12
    at Array.forEach (<anonymous>)
    at Transaction._partialSign (/home/dev-ice/bitoku/test/node_modules/@solana/web3.js/lib/index.cjs.js:1850:13)
    at Transaction.partialSign (/home/dev-ice/bitoku/test/node_modules/@solana/web3.js/lib/index.cjs.js:1841:10)

i tried using all of them as signer but the same error

Update :

i added this extra code

const accountMeta1 = {
  pubkey: pk1.publicKey,
  isSigner: true,
  isWritable: false,
};
const accountMeta2 = {
  pubkey: pk2.publicKey,
  isSigner: true,
  isWritable: false,
};
const accountMeta3 = {
  pubkey: pk3.publicKey,
  isSigner: true,
  isWritable: false,
};
await transaction2.instructions[0].keys.push(accountMeta1);
await transaction2.instructions[0].keys.push(accountMeta2);
await transaction2.instructions[0].keys.push(accountMeta3);

and now i'm getting this error


Error: Signature verification failed
    at Transaction.serialize (/home/dev-ice/bitoku/test/node_modules/@solana/web3.js/lib/index.cjs.js:1933:13)
2
  • Did you try partialSign with all the 3 keypairs and not using sign. I mean in this way transaction2.partialSign([pk1,pk2 ,pk3]) and remove transaction2.sign
    – Pratik.js
    Commented Feb 22, 2023 at 11:53
  • tried it, but the same error Commented Feb 22, 2023 at 12:21

1 Answer 1

0

So this multiSig function works for spl token like here

let wallet = Keypair.fromSecretKey(Uint8Array.from(key));
console.log("wallet", await wallet.publicKey.toBase58());
// 3 keypairs
const pk1 = Keypair.fromSecretKey(Uint8Array.from(key1));
// console.log("wallet 1", pk1.publicKey.toBase58());
const pk2 = Keypair.fromSecretKey(Uint8Array.from(key2));
// console.log("wallet 2", pk2.publicKey.toBase58());
const pk3 = Keypair.fromSecretKey(Uint8Array.from(key3));
// console.log("wallet 3", pk3.publicKey.toBase58());

const multisigKey = Keypair.generate();
// console.log("mullll", multisigKey.publicKey.toBase58());

const hi = await createMultisig(
  connection,
  wallet,
  [pk1.publicKey, pk2.publicKey, pk3.publicKey],
  2,
  multisigKey
);

const mint = await createMint(
  connection,
  wallet,
  wallet.publicKey,
  wallet.publicKey,
  2
);
console.log("mint", mint.toBase58());

const acc1 = await createAccount(
  connection,
  wallet,
  mint,
  hi,
  Keypair.generate()
);

console.log("acc 1", acc1.toBase58());

const acc2 = await createAccount(
  connection,
  wallet,
  mint,
  hi,
  Keypair.generate()
);

console.log("acc2", acc2.toBase58());

const ui = await mintTo(connection, wallet, mint, acc1, wallet, 1000);

console.log("mint to", ui);
const transf = await transfer(connection, wallet, acc1, acc2, hi, 10, [
  pk1,
  pk2,
  pk3,
]);

console.log(transf);

I don't know if it works for non spl-tokens.

1
  • The SPL token multisig only works for SPL tokens, and not for SOL. It does work for wrapped SOL accounts, however. In general, I'd recommend using a more generic multisig over the SPL-token version
    – Jon C
    Commented Mar 6, 2023 at 19:20

Your Answer

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

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