why transaction cost fixed in remix?

Viewed 529

I test the solidity code like this

pragma solidity ^0.8.4;

contract MyContract {
    struct User {
        bool exists;
        address owner;
    }

    mapping(uint256 => string) public names;
    mapping(address => User) public userList;

    constructor() public {
        names[1] = "asdddddd";
        names[2] = "asdf";
        names[3] = "lee";

        userList[msg.sender].owner = msg.sender;
        userList[msg.sender].exists = true;
    }
}

I check the transaction cost and execution cost in remix

gas : 8000000gas
transcation cost : 8000000gas
execution cost : 301829 gas

I understand the exe cost.. but why transaction cost fixed(8,000,000)? I want to check real transaction cost.

How do I do this?

1 Answers

To check the real deployment cost, you can use extension metamask on chrome and importing a real ethereum account! Then you have to choose Injected Web3:

Confirming metamask

Then compile the code and click on deploy. Then this shows up:

Confirming transaction

Click "Confirm" and then metamask pops up and tells you the deployment cost! You can adjust the cost by yourself by changing gas price on metamask pop up!

But it is wiser to use a testnet like Rinkeby to see if your contract works perfect or not! To do so you just need to switch metamask network into Rinkeby test network and do the same things mentioned above!

Network changing

Related