This is my deployment script but I get an error when creating factory instance.
Error deploying contract: TypeError: Class constructor ContractFactory cannot be invoked without 'new'
I have simple counter contract from the example, I’ve build it and generated types.
versions:
forc 0.63.3
fuels 0.94.3
Deployment script.
import { Provider, Wallet } from 'fuels';
import { TestContractFactory } from '@/sway-api'; // Adjust import path as necessary
import dotenv from 'dotenv';
// Load environment variables from .env file
dotenv.config();
const FUEL_NETWORK_URL = "https://testnet.fuel.network/v1/graphql";
const WALLET_PVT_KEY = process.env.NEXT_PUBLIC_WALLET_PVT_KEY || "";
console.log("WALLET_PVT_KEY: ", WALLET_PVT_KEY);
async function deployContract() {
try {
// Create the provider
const provider = await Provider.create(FUEL_NETWORK_URL);
console.log("Provider initialized successfully");
// Create the wallet
const wallet = Wallet.fromPrivateKey(WALLET_PVT_KEY, provider);
console.log("Wallet created successfully");
// Create a factory instance with the correct `new` keyword
const factory = new TestContractFactory(wallet);
console.log("Factory instance created");
// Deploy the contract using the factory instance
const deployResult = await factory.deploy();
console.log("Deploy initiated");
// Wait for deployment results
const { contract, transactionResult } = await deployResult.waitForResult();
console.log('Contract deployed successfully with ID:', contract);
console.log('Transaction ID:', transactionResult.id);
} catch (error) {
console.error("Error deploying contract:", error);
}
}
deployContract().catch(console.error);
This is generated TestContractFactory.ts
/* Autogenerated file. Do not edit manually. */
/* eslint-disable max-classes-per-file */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/consistent-type-imports */
/*
Fuels version: 0.94.3
*/
import { ContractFactory, decompressBytecode } from "fuels";
import type { Provider, Account, DeployContractOptions, DeployContractResult } from "fuels";
import { TestContract } from "./TestContract";
const bytecode = decompressBytecode("H4sIAAAAAAAAA61YT2wc1Rn/drObLI4Tj+11ccdFnqIlXSqhblsnclokz2h3OrvZrPa5jknastlVaVTn0NRdxVYEAg9EqnyoVIME5IBEEAJx4DBr5xAEhxVw4MAhQhwCAskcgmIRS3sAyYZD+H1v3mwm400QEpZW7837833f+97v+33fs97J0VmiOMm/Q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WxFozzN/On+vaY74P9zEdyHPySBs9qOMt16Lkv8l5p3HqvtLjulRwmOe4vadxtA7iAf7dFFH8/RW2zZwjceJf6Jsx9fk12HHcM3lPxFuRDlatu544FoouKO1in5A6cke+T9+2oObD+5UhOPCK5TGJWYqFxp5yIfHE69GYKciLzgMqJratqTuXE1hX+juREuT+SE/lN2DMnwt4vVU6cYvnA4hR4+Q/gtRWfX5LuYTvx0Um82yFnCvNcl3ff67JO9s/K3B+vW4JzWuKk38Z9LjpmRmR7Mt9WkuYfK4k/w97USRv++FrmL9TAO3gqjJMVPY+YdjpD/P7FG2aY3zA+F6XbzFmQ57912N+OxHOR43PnXcVLfLeKt1b0bboNO/88dbb+2L8XznC9z3+nzzzWPPWvU2fU6KmmGj/z8BPV02/f/M/v3nvv9ez51//7f8d759dLv2zUH9z1v09eW69/KP+C/8MMNPx2/z/8dt9nqv1YtR+q9n3VgoVk+7BSt6xa93sgil6s4BEAAA==");
export class TestContractFactory extends ContractFactory {
static readonly bytecode = bytecode;
constructor(accountOrProvider: Account | Provider) {
super(bytecode, TestContract.abi, accountOrProvider);
}
static async deploy (
wallet: Account,
options: DeployContractOptions = {}
): Promise<DeployContractResult<TestContract>> {
const factory = new TestContractFactory(wallet);
return factory.deploy({
storageSlots: TestContract.storageSlots,
...options,
});
}
}