Search code examples
node.jsblockchainsolidityhedera-hashgraphhashgraph

Hedera Transaction Oversize error : TypeError: ContractCreateFlow is not a constructor


The below code throws "Transaction Oversize" error

const contractBytecode = fs.readFileSync("TestToken_sol_TestToken.bin");
const fileCreateTx = new FileCreateTransaction()
    .setContents(contractBytecode)
    .setKeys([operatorKey])
    .freezeWith(client);    
const fileCreateSign = await fileCreateTx.sign(operatorKey);
const fileCreateSubmit = await fileCreateSign.execute(client);
const fileCreateRx = await fileCreateSubmit.getReceipt(client);
const bytecodeFileId = fileCreateRx.fileId;
console.log(`- The bytecode file ID is: ${bytecodeFileId} \n`);

But trying out solution provided here, I ran into this new error "ContractCreateFlow is not a constructor" :

const contractInstantiateTx = new ContractCreateFlow()
.setGas(100000)
.setBytecode(contractBytecode)

const contractInstantiateSubmit = await contractInstantiateTx.execute(client);
const contractInstantiateRx = await contractInstantiateSubmit.getReceipt(client);

const contractId = contractInstantiateRx.contractId;
const contractAddress = contractId.toSolidityAddress();
console.log(`- The smart contract ID is: ${contractId} \n`);
console.log(`- The smart contract ID in Solidity format is: ${contractAddress} \n`);

Solution

  • Please see this answer: Getting error "Transaction Oversize" while creating a smart contract in Hedera blockchain You may need to import the ContractCreateFlow() module into your program from the SDK. Check the SDK version you're using as ContractCreateFlow() was introduced in v2.14 of the JS SDK.

    As an alternative, see this example if you wish to use FileCreate, FileAppend, and Contract create modules:

    //Create a file on Hedera and store the hex-encoded bytecode
    const fileCreateTx = await new FileCreateTransaction().setKeys([adminKey]).execute(client);
    const fileCreateRx = await fileCreateTx.getReceipt(client);
    const bytecodeFileId = fileCreateRx.fileId;
    console.log(`- The smart contract bytecode file ID is: ${bytecodeFileId}`);
    
    // Append contents to the file
    const fileAppendTx = await new FileAppendTransaction()
        .setFileId(bytecodeFileId)
        .setContents(bytecode)
        .setMaxChunks(10)
        .setMaxTransactionFee(new Hbar(2))
        .execute(client);
    await fileAppendTx.getReceipt(client);
    console.log(`- Content added`);
    
    console.log(`\nSTEP 2 - Create contract`);
    const contractCreateTx = await new ContractCreateTransaction()
        .setAdminKey(adminKey)
        .setBytecodeFileId(bytecodeFileId)
        .setGas(100000)
        .execute(client);
    
    const contractCreateRx = await contractCreateTx.getReceipt(client);
    const contractId = contractCreateRx.contractId.toString();
    console.log(`- Contract created ${contractId}`);
    

    If you don't use ContractCreateFlow(), you first create an empty file, then append content (by chunks), and then create the contract - as shown by the code above.