我的 bin 文件大小只有 18kb。我还得到了使用 IPFS 的解决方案,但不知道如何使用它。如果有任何使用 IPFS 的参考,请分享给我。 :
错误:PrecheckStatusError:交易[电子邮件受保护] /cdn-cgi/l/email-protection预检查失败,状态为 TRANSACTION_OVERSIZE
这是我的代码:
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();
您遇到了 TRANSACTION_OVERSIZE 错误,因为 Hedera 交易的大小限制为 6kb(包括所有签名)。
如果你的合约编译后的字节码比较大,那么你需要在 Hedera 上创建一个文件,然后将内容分多个块附加,然后创建合约。
现在,当您使用时,SDK 会为您处理这 3 个步骤ContractCreateFlow()
.这是一个例子:
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);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)