首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Hedera区块链中创建智能契约时获取错误“事务超大”

在Hedera区块链中创建智能契约时获取错误“事务超大”
EN

Stack Overflow用户
提问于 2022-05-27 13:51:25
回答 1查看 248关注 0票数 2

我的垃圾箱文件大小只有18 is。我还得到了一个使用IPFS的解决方案,但不知道如何使用它。如果有任何使用IPFS的参考资料,请与我分享。:

错误: PrecheckStatusError:事务0.0.34898094@1653658245.135892060失败的precheck与状态TRANSACTION_OVERSIZE

这是我的代码:

代码语言:javascript
复制
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();
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-06-17 18:47:52

您正碰到TRANSACTION_OVERSIZE错误,因为Hedera事务的大小限制为6kb,包括所有签名。

如果您的契约的已编译字节码相对较大,那么您将需要在Hedera上创建一个文件,然后将内容附加到多个块中,然后创建契约。

现在,当您使用ContractCreateFlow()时,SDK将为您处理这三个步骤。下面是一个示例:

代码语言:javascript
复制
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);
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72406476

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档