I've written this ink! quickstart script that I can repeatedly call to run these steps to flood my local testnet with instances of Flipper contracts:

  1. Kills an existing substrate-contracts-node running on default port 30333
  2. Kills the associated database
  3. Starts the substrate-contracts-node again
  4. Waits for 15 seconds that seems to be an adequate amount of time before interacting with it to avoid errors like ERROR: Rpc error: RPC error: Networking or low-level protocol error: Error when opening the TCP socket: Cannot assign requested address (os error 99)
  5. Creates the Flipper DApp boilerplate
  6. Builds the Flipper smart contract
  7. Updates the Flipper DApp ABI with the latest build of flipper.json
  8. Uploads the smart contract to a Code Hash
  9. Instantiates the smart contract at a Contract Address
  10. Calls various smart contract functions

But I can't just have the script only do steps 5-10 repeatedly because I'll get error ERROR: This contract has already been uploaded with code hash:. Hence why I destroy the chain database before restarting the node and uploading and deploying the smart contract again. But each time the substrate-contracts-node restarts and I upload and instantiate it, it always gets uploaded to the same Code Hash and is instantiated with the same Contract Address.

In step 9. where we're instantiating the contract at a Contract Address with this command:

cargo contract instantiate --suri //Bob --constructor new --args true --execute --skip-confirm | tail -1

I can't instantiate it again with the same --suri //Bob or it gives error:

ERROR: ModuleError: Contracts::DuplicateContract: ["A contract with the same AccountId already exists."]

If I change it to --suri //Charlie so a different account instantiates the smart contract it actually generates a different Contract Address. So I could flood the local testnet with multiple instances of the same contract as long as I generate a unique account to instantiate each one.

But in earlier step 8. where we're uploading the contract with this command:

cargo contract upload --suri //Alice --execute --skip-confirm | tail -1

If I change it to --suri //Bob so a different account uploads the smart contract it still generates the same Code Hash and returns error:

ERROR: This contract has already been uploaded with code hash: 0x__

Question: So is it possible to upload exactly the same same ink! smart contract code multiple times on the same network with a different Code Hash? Or is the only possible way to do that by adding an extra step to slightly modify the smart contract code that would be getting built and uploaded?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.