2

I am trying to deploy a contract. I get the contract address without errors. Immediately after deploy, the contract is deleted. Although it is possible to transfer funds to the contract address without errors. What could be the problem?

https://github.com/PavelZavadskiy/uniswap_permit2

let esealCompiled = require('../artifacts/contracts/Permit2.sol/Permit2.json');
const bytecode = esealCompiled.bytecode;

const contractTx = new ContractCreateFlow()
.setGas(3000000)
.setBytecode(bytecode)
.setAutoRenewAccountId(myDefaultAccountId);

//Submit the transaction to the Hedera test network
const contractResponse = await contractTx.execute(client);

//Get the receipt of the file create transaction
const contractReceipt = await contractResponse.getReceipt(client);

//Get the smart contract ID
const newContractId = contractReceipt.contractId;

//Log the smart contract ID
console.log('The smart contract ID is ' + newContractId);

const transaction = new TransferTransaction()
.addHbarTransfer(myDefaultAccountId, new Hbar(-10))
.addHbarTransfer(newContractId.toString(), new Hbar(10));

//Submit the transaction to a Hedera network
const txResponse = await transaction.execute(client);

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

//Get the transaction consensus status
const transactionStatus = receipt.status;`

Recent transaction

Transaction contract create

Transaction file delete

evolutionxbox
  • 3,932
  • 6
  • 34
  • 51
Pavel
  • 21
  • 3

2 Answers2

0

This is the correct behavior. The file with the uploaded contract bytecodes is needed only until the contract is created. The contract create transaction itself makes a copy of the bytecodes to keep in the file store. (And it only keeps the runtime bytecode, not the initcode.)

You can actually see the delete in the java SDK here.

(The distinction might be interesting in the future when Hedera turns on rent for files and contracts: At that time the rent-payer for the contract will be paying for its bytes in storage, not whoever uploaded the contract bytecodes. They might be different accounts!)

davidbak
  • 5,775
  • 3
  • 34
  • 50
0

Here is the link in docs that describes how Contract Create Flow works https://docs.hedera.com/hedera/sdks-and-apis/sdks/smart-contracts/create-a-smart-contract#contractcreateflow.

If you want to retain the file and have access to the file ID you do not need to use the contract create flow method. You can perform the manual steps:

(1) Create a file that stores your contract bytecode (FileCreateTransaction) (2) Create and deploy the contract using the ContractCreateTransaction

See example here: https://docs.hedera.com/hedera/tutorials/smart-contracts/deploy-your-first-smart-contract

  • This would be useful if for some reason you wanted to deploy the exact same contract more than once (to different addresses). – davidbak Aug 18 '23 at 00:00