2

I cloned a tic tac toe game repository to understand the logic of smart contracts and rust. It is working on moralis and need two player wallet addresses to play/create a game but when I add the second Phantom wallet ( both of them are my wallet but with different addresses) I am getting this error:


wait  - compiling /api/TicTacToe/newGame...
event - compiled successfully in 101 ms (51 modules)
error - Error: bad secret key size
    at Function.fromSecretKey (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/@solana/web3.js/lib/index.cjs.js:7497:13)
    at handler (webpack-internal:///(api)/./pages/api/TicTacToe/newGame.ts:23:74)
    at Object.apiResolver (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/next/dist/server/api-utils/node.js:184:15)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async DevServer.runApi (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/next/dist/server/next-server.js:403:9)
    at async Object.fn (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/next/dist/server/base-server.js:493:37)
    at async Router.execute (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/next/dist/server/router.js:222:36)
    at async DevServer.run (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/next/dist/server/base-server.js:612:29)
    at async DevServer.run (/home/aleyna/tmp/solana-smart-contract-tic-tac-toe/node_modules/next/dist/server/dev/next-dev-server.js:569:20) {
  page: '/api/TicTacToe/newGame'
}



I can understand that the problem is related with my secret key size but I dont know how to fix it.

blackgreen
  • 34,072
  • 23
  • 111
  • 129

1 Answers1

1

This error is possibly from this line of the code. It uses joined address strings of length 5 to create a unique secret for PDA account creation.

// Account Creation --- Start
const GAME_ACCOUNT_SECRET = `${player1.substring(0, 5)}${player2.substring(0, 5)}`;

Try updating it to this line by reducing the substring length to 4 or less.

const GAME_ACCOUNT_SECRET = `${player1.substring(0, 4)}${player2.substring(0, 4)}`;
JohnVersus
  • 123
  • 1
  • 10