1

I am new to Ethereum, learning about smart contracts.
I have a simple hello world contract.

# @version ^0.3.7

@external
@pure
def hola() -> String[5]:
    return "hola!"

Currently, I'm doing experiments to find out how much wei it costs to deploy a contract.

When I deploy my contract to Ganache UI, its log shows two transactions, with two separate gas fees.

Question: I only expect one transaction. Why are there two?


Ganache Log:

[5:23:15 PM]   Transaction: 0x1fd75f313be224fb941c37d62548c0e68cba47ce61f99a2c5d2ff0db646418d2
[5:23:15 PM]   Contract created: 0x56f36098ae392a06540387ffa56ea43624e806e7
[5:23:15 PM]   Gas usage: 201627
[5:23:15 PM]   Block Number: 6
[5:23:15 PM]   Block Time: Tue Feb 07 2023 17:23:15 GMT+0700 (Indochina Time)
[5:23:15 PM] eth_getTransactionReceipt[5:23:15 PM] eth_getBlockByNumber
[5:23:15 PM] eth_getCode[5:23:15 PM] eth_getBlockByNumber
[5:23:15 PM] eth_getBlockByNumber[5:23:15 PM] eth_estimateGas
[5:23:15 PM] eth_getBlockByNumber[5:23:15 PM] eth_gasPrice
[5:23:15 PM] eth_sendTransaction
[5:23:15 PM]   Transaction: 0xeb19faa88d021e2e94e2a89a5718b64793e8e47936bff2dc9008bb22c298f297
[5:23:15 PM]   Gas usage: 42513
[5:23:15 PM]   Block Number: 7
[5:23:15 PM]   Block Time: Tue Feb 07 2023 17:23:15 GMT+0700 (Indochina Time)

Truffle config:

  networks: {
    development: {
      host: "127.0.0.1",
      port: 7545,
      network_id: "*",
    }

Test/Deploy code:

const Hello = artifacts.require("Hello");
contract("Hello Only", () => {
  it("...should deploy", async () => {
    const hello = await Hello.deployed();
  });
});
7
  • 2
    truffle deploy a migration contract, this must be excluded somehow when deployen to mainnet. check this ethereum.stackexchange.com/questions/8299/…
    – Majd TL
    Feb 7 at 12:48
  • 1
    that's why I stopped used truffle, when I discovered they store deployment info on the chain. what a horrible design idea
    – Nulik
    Feb 7 at 17:23
  • @Nulik I agree. After posting, I found several other Truffle questions and bug reports expressing the same bewilderment. I won't use Truffle again.
    – devdanke
    Feb 8 at 15:27
  • @devdanke the best way to deploy is to use scripts in golang. there is abigen command for that, it will create constructor with parameters and also wrapper for all the functions. I am compiling contracts with solc to produce combined json format and then just do: abigen --combined-json artifacts.json --pkg whatever ..etc....
    – Nulik
    Feb 9 at 0:51
  • @Nulik I'm having success with the Web3j Ethereum client. It can be used in Java, Kotlin, Scala, and Clojure etc. It can also be used in Android apps.
    – devdanke
    Feb 9 at 14:04

2 Answers 2

1

Truffle deploys an extra migration contract. check this question What are truffle migrations? for more information about it.

This migration contract should be excluded somehow when deployen to mainnet or run the tests.

-1

The first one, with gas usage: 201627, is for the creation of the contract (deploying to the network). The fees after that is to run the contract on the network.

1
  • No. The second transaction isn't to "run" the contract. Instead, (I learned from @Majd TL) the second transaction posts meta data about my contract to a Truffle migration history contract. As you can see in my test code above, after deployment, there is no other interaction with my contract.
    – devdanke
    Feb 8 at 15:34

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.