I'm deploying a Mina zkApp server-side using o1js and encountering this error:
Error: @method decorator was applied to [object Object], which is not a function.
at method (/path/to/zkapp.ts:118:11)
...
Here's my setup:
- Game Contract Code:
import { SmartContract, method, state, State, PublicKey, UInt64 } from 'o1js';
export class GameContract extends SmartContract {
@state(PublicKey) player1 = State<PublicKey>();
@state(PublicKey) player2 = State<PublicKey>();
@state(UInt64) totalAmount = State<UInt64>();
@method async initGame(player1Address: PublicKey, player2Address: PublicKey) {
this.player1.set(player1Address);
this.player2.set(player2Address);
this.send({ to: this.address, amount: UInt64.from(1_000_000_000) });
}
.....
}
2. Contract Deployment (Server-Side):
import { PrivateKey, PublicKey, UInt64, Mina, AccountUpdate } from "o1js";
import { GameContract } from "../../contracts/src/Game";
async function deployGameContract(
deployerKey: PrivateKey,
players: PublicKey[]
): Promise<{ zkAppAddress: string; txId: string }> {
const zkAppPrivateKey = PrivateKey.random();
const zkAppAddress = zkAppPrivateKey.toPublicKey();
const zkAppInstance = new GameContract(zkAppAddress);
const Network = Mina.Network("https://api.minascan.io/node/devnet/v1/graphql");
Mina.setActiveInstance(Network);
const deployTransaction = await Mina.transaction(
{
sender: deployerKey.toPublicKey(),
fee: UInt64.from(1_000_000),
},
async () => {
AccountUpdate.fundNewAccount(deployerKey.toPublicKey());
zkAppInstance.deploy(); // Deploy zkApp
zkAppInstance.initGame(players[0], players[1]);
}
);
...
}
Additional Information:
This code is executed server-side.
Node version: 22.3.0.
Could the issue be due to my TypeScript setup or Node version compatibility with o1js? Any guidance would be appreciated!