#Factory

7 messages · Page 1 of 1 (latest)

winter crypt
#

I am trying to create a factory contract that will create new contract and store addresses of created accounts.

There was discussion here about this topic https://discord.com/channels/484437221055922177/1123378515207786606, but deploy method of contract can't accept public key from contract argument(only constant), which make it quite useless.

I have tried to set verification key of new contact directly with following code(by the way there is no way to pass data, as it is string. How it supposed to be used?)

  @method async deploySubject(newAddress: PublicKey, verificationKey: Field) {
    const subject = new Subject(newAddress);

    AccountUpdate.create(newAddress).account.verificationKey.set({
      data: '<data from Subject.compile>',
      hash: verificationKey,
    });
  }

Call it with

    const txn = await Mina.transaction(senderAccount, async () => {
      await zkApp.deploySubject(subject, subjectComp.verificationKey.hash);
      AccountUpdate.fundNewAccount(senderAccount);
    });

    await txn.prove();
    await txn.sign([senderKey, subjectPrivateKey]).send();

But it gives we following error

Transaction failed with errors:
    - [[],[["Cancelled"]],[["Update_not_permitted_verification_key"]],[["Cancelled"]]]

Any idea on how to fix it? Or may be there is different approach to solve factory problem?

brittle cairn
brittle cairn
winter crypt
winter crypt
#

@brittle cairn Is there is a way to call init somehow for contract deployed via factory?

Tried call it in deployment method, and explicitly, but get "Update_not_permitted_app_state" error

minor spoke
# winter crypt <@401088306210799616> Is there is a way to call init somehow for contract deploy...

Init means that you're setting the initial account state. You can do it directly in your method as in this example:

const state = [ // 8 Fields
      name,
      ...MetadataParams.toFields(metadataParams),
      ...owner.toFields(),
      new NFTparams({
        price,
        version: UInt32.from(1),
      }).pack(),
    ];
    update.body.update.appState = state.map((field) => ({
      isSome: Bool(true),
      value: field,
    }));

https://github.com/dfstio/minanft-lib/blob/master/src/contract-v2/nft.ts#L294

winter crypt