My bin file size is 18kb only. I also get a solution to use IPFS but don't know how to use it. If there is any reference for using IPFS then share me plz. :
Error: PrecheckStatusError: transaction [email protected] failed precheck with status TRANSACTION_OVERSIZE
Here is my code :
const {
AccountId,
PrivateKey,
Client,
FileCreateTransaction,
ContractCreateTransaction,
ContractFunctionParameters,
ContractExecuteTransaction,
ContractCallQuery,
Hbar
} = require("@hashgraph/sdk");
const fs = require("fs");
const operatorId = AccountId.fromString(process.env.OPERATOR_ID);
const operatorKey = PrivateKey.fromString(process.env.OPERATOR_PVKEY);
const client = Client.forTestnet().setOperator(operatorId, operatorKey);
async function main() {
// Import the compiled contract bytecode
const contractBytecode = fs.readFileSync("first_contract_sol_ABC_TOKEN.bin");
// Create a file on Hedera and store the bytecode
const fileCreateTx = new FileCreateTransaction().setContents(contractBytecode).setKeys([operatorKey]).setMaxTransactionFee(new Hbar(1))
.freezeWith(client);
const fileCreateSign = await fileCreateTx.sign(operatorKey);
console.log(Date.now() / 1000);
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`);
// Instantiate the smart contract
const contractInstantiateTx = new ContractCreateTransaction()
.setBytecodeFileId(bytecodeFileId)
.setGas(100000)
.setConstructorParameters(
new ContractFunctionParameters().addString("Alice").addUint256(111111)
);
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(`- Smart contract ID in Solidity format: ${contractAddress} \n`);
}
main();
You are hitting the TRANSACTION_OVERSIZE error because Hedera transactions have a 6kb size limit including all signatures.
If the compiled bytecode for your contract is relatively large, then you will need to create a file on Hedera, then append the contents in multiple chunks, and then create the contract.
The SDK now handles those 3 steps for you when you use
ContractCreateFlow()
.Here's an example: