简体   繁体   English

在 Hedera 区块链中创建智能合约时出现错误“交易过大”

[英]Getting error "Transaction Oversize" while creating a smart contract in Hedera blockchain

My bin file size is 18kb only.我的 bin 文件大小只有 18kb。 I also get a solution to use IPFS but don't know how to use it.我也得到了使用 IPFS 的解决方案,但不知道如何使用它。 If there is any reference for using IPFS then share me plz.如果有任何使用 IPFS 的参考,请分享给我。 :

Error: PrecheckStatusError: transaction 0.0.34898094@1653658245.135892060 failed precheck with status TRANSACTION_OVERSIZE错误:PrecheckStatusError:事务 0.0.34898094@1653658245.135892060 预检查失败,状态为 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.您遇到了 TRANSACTION_OVERSIZE 错误,因为 Hedera 事务的大小限制为 6kb,包括所有签名。

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.如果为你的合约编译的字节码比较大,那么你需要在 Hedera 上创建一个文件,然后将内容附加到多个块中,然后创建合约。

The SDK now handles those 3 steps for you when you use ContractCreateFlow() .Here's an example:当您使用ContractCreateFlow()时,SDK 现在会为您处理这 3 个步骤。下面是一个示例:

const contractCreate = new ContractCreateFlow()
    .setGas(100000)
    .setBytecode(bytecode);

//Sign the transaction with the client operator key and submit to a Hedera network
const txResponse = contractCreate.execute(client);

//Get the receipt of the transaction
const receipt = (await txResponse).getReceipt(client);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Hedera Transaction Oversize 错误:TypeError:ContractCreateFlow 不是构造函数 - Hedera Transaction Oversize error : TypeError: ContractCreateFlow is not a constructor 使用Web 3连接到智能合约时出错 - Getting error while connecting to smart contract using web 3 我们可以更新部署在 Hedera 测试网中的 Solidity 智能合约吗? - Can we update solidity smart contract which is deployed in Hedera TestNet? 通过 Hardhat 将智能合约部署到孟买 tes.net 时出错 - Error while deploying a smart contract to Mumbai testnet through Hardhat 测试私有区块链中的代码并部署智能合约 - Testing a code from a private blockchain and deploy a smart contract 处理智能合约交易快递Node.js - Handle smart contract transaction express nodejs 使用 Node.js 编译和部署以太坊智能合约时出错 - Getting error when compiling and deploying ethereum smart contract with Node.js 使用 nodejs 进行智能合约测试失败并显示错误消息 - Smart Contract test with nodejs fails with an error message 部署智能合约时获取“未定义”的参数数量无效 - Getting Invalid number of parameters for “undefined” when deploying smart contract 在 VScode 中编译智能合约时出现问题(终端无响应) - Problem while compiling smart contract in VScode ( No response in temrinal )
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM