EDIT: Ok this works. I just pass in the wallet seed manually and create a Signer, I'd still like to get it working with a wallet though.
const initializeGame = async (wallet: AnchorWallet, connection: Connection): Promise<void> => {
if (!wallet) return;
const seed = new Uint8Array([numbers here])
const keypair = Keypair.fromSecretKey(seed)
const sign: Signer = {
publicKey: keypair.publicKey,
secretKey: seed
}
let [gameAcctPDA] = web3.PublicKey.findProgramAddressSync(
[Buffer.from( "game" ), keypair.publicKey.toBuffer()],
PROGRAM_ID
);
console.log('gameAcct: ', gameAcctPDA.toString());
let [wordVaultAcctPDA] = web3.PublicKey.findProgramAddressSync(
[Buffer.from("word"), keypair.publicKey.toBuffer()],
PROGRAM_ID
);
console.log('wordVaultAcct: ', wordVaultAcctPDA.toString())
let [moneyVaultAcctPDA, bump] = web3.PublicKey.findProgramAddressSync(
[Buffer.from("pot")],
PROGRAM_ID
);
console.log('moneyVaultAcct: ', moneyVaultAcctPDA.toString())
const gameAccounts: InitializeCreateGameInstructionAccounts = {
game: gameAcctPDA,
wordVault: wordVaultAcctPDA,
moneyPotVault: moneyVaultAcctPDA,
owner: sign.publicKey
}
const gameCreationArgs: InitializeCreateGameInstructionArgs = {
name: 'TestVerse',
minDeposit: 0.1
}
const transactionInstruction = createInitializeCreateGameInstruction(gameAccounts, gameCreationArgs);
try {
const tx = new Transaction().add(transactionInstruction);
tx!.feePayer = sign!.publicKey!;
const latestBlockhash = await connection.getLatestBlockhash();
tx.recentBlockhash = latestBlockhash.blockhash;
tx!.sign(sign);
// await wallet?.signTransaction(tx);
// Serialize and send the transaction
const signedTx = tx!.serialize();
const txId = await connection.sendRawTransaction(signedTx);
console.log('Transaction ID:', txId);
} catch (error) {
console.log('error creating game', error);
}
};
return { initializeGame };