o1-labs / o1js

TypeScript framework for zk-SNARKs and zkApps

Home Page:https://docs.minaprotocol.com/en/zkapps/how-to-write-a-zkapp

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Can not deploy `SmartContract` in 0.18.0

Pfed-prog opened this issue · comments

Nothing Works and I do not know why.

working code in 0.17.0

export async function deployNFTContract(
  pkSender: PrivateKey,
  pkNFTContract: PrivateKey,
  proofsEnabled: boolean = true,
  live: boolean = true
): Promise<TxStatus> {
  let verificationKey: VerificationKey | undefined;
  if (proofsEnabled) {
    ({ verificationKey } = await NFTContract.compile());
  }
  const zkAppAddress: PublicKey = pkNFTContract.toPublicKey();
  const zkAppInstance: NFTContract = new NFTContract(zkAppAddress);
  const pubKey: PublicKey = pkSender.toPublicKey();
  const deployTxnOptions: TxOptions = createTxOptions(pubKey, live);
  const deployTx: Transaction = await Mina.transaction(deployTxnOptions, () => {
    AccountUpdate.fundNewAccount(pubKey);
    zkAppInstance.deploy({ verificationKey, zkappKey: pkNFTContract });
  });
  const txStatus: TxStatus = await sendWaitTx(deployTx, [pkSender], live);
  return txStatus;
}

Should I keep { verificationKey, zkappKey: pkNFTContract } in deploy ?
Should I wrap deploy in async/await ?

image

Unfortunately, the contract still does not deploy
image

Sharing highlighted errors

These disappear after async is added to deploy
image

image

These disappear after @method public are removed
image

These ones seem to be actually improvements and I really liked that we could access contract instance
image

Another try

image

Bool was returning just fine in previous version

zkappKey moved to sign

everything is wrapped in async/await

export async function deployNFTContract(
  pkSender: PrivateKey,
  pkNFTContract: PrivateKey,
  compile: boolean = true,
  live: boolean = true
): Promise<TxStatus> {
  let nftContractverificationKey: VerificationKey | undefined;
  if (compile) {
    const { verificationKey } = await NFTContract.compile();
    nftContractverificationKey = verificationKey;
  }

  const zkAppAddress: PublicKey = pkNFTContract.toPublicKey();
  const zkAppInstance: NFTContract = new NFTContract(zkAppAddress);
  const pubKey: PublicKey = pkSender.toPublicKey();
  const deployTxnOptions: TxOptions = createTxOptions(pubKey, live);
  const deployTx: Transaction = await Mina.transaction(
    deployTxnOptions,
    async () => {
      AccountUpdate.fundNewAccount(pubKey);
      await zkAppInstance.deploy({
        verificationKey: nftContractverificationKey,
      });
    }
  );
  const txStatus: TxStatus = await sendWaitTx(
    deployTx,
    [pkSender, pkNFTContract],
    live
  );
  return txStatus;
}