Failed to migrate a smart contract using truffle, please help

I have some truble on migrate smart contract using infura on the mainnet of eth.

The truffle-config.js is as below:

const HDWalletProvider = require('truffle-hdwallet-provider');

module.exports = {
  networks: {
    mainnet: {
      provider: new PrivateKeyProvider("my private key", "https://mainnet.infura.io/v3/my project id"),
      network_id: 1,       // Ropsten's id
    }
  }

I use truffle migrate --network mainnet and get the message:

Compiling your contracts...
===========================
> Everything is up to date, there is nothing to compile.


Migrations dry-run (simulation)
===============================
> Network name:    'mainnet-fork'
> Network id:      1
> Block gas limit: 0x7a121d


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
   > account:             0xEb510b7a46064Cc5B8726c77AF9f6dFCEAe02000
   > balance:             0.057450184
   > gas used:            269908
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.000539816 ETH

   -------------------------------------
   > Total cost:         0.000539816 ETH


2_deploy_contracts.js
=====================

   Deploying 'GreatPay'
   --------------------
   > account:             0xEb510b7a46064Cc5B8726c77AF9f6dFCEAe02000
   > balance:             0.05583689
   > gas used:            779613
   > gas price:           2 gwei
   > value sent:          0 ETH
   > total cost:          0.001559226 ETH

   -------------------------------------
   > Total cost:         0.001559226 ETH


Summary
=======
> Total deployments:   2
> Final cost:          0.002099042 ETH


Starting migrations...
======================
> Network name:    'mainnet'
> Network id:      1
> Block gas limit: 0x7a1200


1_initial_migration.js
======================

   Deploying 'Migrations'
   ----------------------
Error:  *** Deployment Failed ***

"Migrations" could not deploy due to insufficient funds
   * Account:  0xEb510b7a46064Cc5B8726c77AF9f6dFCEAe02000
   * Balance:  57990000000000000 wei
   * Message:  insufficient funds for gas * price + value
   * Try:
      + Using an adequately funded account
      + If you are using a local Geth node, verify that your node is synced.

    at /usr/local/lib/node_modules/truffle/build/webpack:/packages/truffle-deployer/src/deployment.js:364:1
    at <anonymous>
    at process._tickCallback (internal/process/next_tick.js:188:7)
Truffle v5.0.10 (core: 5.0.10)
Node v8.10.0

I am sure I have enough eth in my account, but what happened. Please help.

Riley,

I see your transactions as having gone through on etherscan:

https://etherscan.io/address/0xeb510b7a46064cc5b8726c77af9f6dfceae02000

Did you change anything on your end or simply try the migration again? If you could please let us know what you tried to resolve the issue it’ll help us further debug how the migration might’ve failed the first time.

Thanks!
Ryan

Yes.

Yesterday I find a blog Deploy Your Smart Contract Directly from Truffle with Infura and find he set the gasPrice. So I think it maight the default gas price is not good enough. I change the truffle-config.js as below:

const HDWalletProvider = require('truffle-hdwallet-provider');

module.exports = {
  networks: {
    mainnet: {
      provider: new PrivateKeyProvider("my private key", "https://mainnet.infura.io/v3/my project id"),
      network_id: 1,       // Ropsten's id
      gas: 3000000,
      gasPrice: 10000000000
    }
  }
}

Then everything works fine.

now suppose I am calculating my costing for total gas* gas price is around 0.2. Is there any calculation that what amount I need to keep in my wallet balance?

@Rakib_Hossain you should have enough ETH in the wallet balance to be able to pay for the migration.
Have you encountered any errors so far?

yes. I got this message

Starting migrations…

Network name: ‘live’
Network id: 1
Block gas limit: 29970676 (0x1c950f4)

1_initial_migration.js

Deploying ‘Migrations’

transaction hash: 0xf768f693f09f2f4aaf36713796fc3e41bda94305e4b2697ef4c4e70d92ef7c6e
Blocks: 1 Seconds: 8
contract address: 0xEcb3f242443bdA5Dc1e24d083238216314387f60
block number: 14352003
block timestamp: 1646821347
account: 0xEa63AA1670034632E6fAEC3cC5Aee497C5E6667C
balance: 0.666391637183119593
gas used: 176717 (0x2b24d)
gas price: 35 gwei
value sent: 0 ETH
total cost: 0.006185095 ETH

⠙ Saving migration to chain.
Error: replacement transaction underpriced
at Migration._deploy (/usr/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:99:1)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at Migration._load (/usr/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:56:1)
at Migration.run (/usr/lib/node_modules/truffle/build/webpack:/packages/migrate/Migration.js:217:1)
at Object.runMigrations (/usr/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:150:1)
at Object.runFrom (/usr/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:110:1)
at Object.run (/usr/lib/node_modules/truffle/build/webpack:/packages/migrate/index.js:87:1)
at runMigrations (/usr/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:76:1)
at Object.module.exports [as run] (/usr/lib/node_modules/truffle/build/webpack:/packages/core/lib/commands/migrate/run.js:44:1)
at Command.run (/usr/lib/node_modules/truffle/build/webpack:/packages/core/lib/command.js:189:1)
Truffle v5.4.26 (core: 5.4.26)
Node v16.13.1

Where i set gasprice :35gwei
I see gasprice that time not more then 30