Warum kostet die Bereitstellung dieses Vertrags 1 Eth?

Truffle sagt mir, dass der Einsatz 1 Eth kostet. Sind das ernsthaft die Kosten für die Bereitstellung eines einfachen Vertrags (dies ist meine erste Mainnet-Bereitstellung)? Oder geht da noch was?

 mainnet: {
      provider: () =>
        new HDWalletProvider({
          mnemonic: { phrase: process.env.MNEMONIC },
          providerOrUrl: process.env.RPC_URL_1_WSS,
        }),
      network_id: 1, // Main's id
      from: process.env.DEPLOYERS_ADDRESS,
      gas: 4712388, // Gas limit used for deploys. Default is 4712388.
      gasPrice: 211000000000, //Gas price in Wei
      confirmations: 2, // # of confs to wait between deployments. (default: 0)
      timeoutBlocks: 200, // # of blocks before a deployment times out  (minimum/default: 50)
      skipDryRun: false, // Skip dry run before migrations? (default: false for public nets )
    },
  },
pragma solidity ^0.7.4;

import "@chainlink/contracts/src/v0.6/interfaces/AggregatorV3Interface.sol";
import "@openzeppelin/contracts/math/SafeMath.sol";


contract EthMsg {
  address payable public owner;
  uint public messagesSentCount = 0;

  uint decimals = 8;
  uint scale = 10**decimals;

  uint public txtPriceUSD = 1.70 * 10**8;
  uint public txtPriceEth;

  using SafeMath for uint;

  AggregatorV3Interface internal priceFeed;

  event Spend(
    string textMsg,
    string recipient
  );
  event TextMsgError(
    string reason
  );

  constructor(address oracleAddress) {
    owner = msg.sender;
    priceFeed = AggregatorV3Interface(oracleAddress);
  }

  function sendTextMessage(
    string calldata textMsg,
    string calldata recipient
  ) external payable returns(bool) {

    (uint newTxtPriceEth,,) = this.pollTxtPrices();

    require(
      msg.value > newTxtPriceEth,
      'Please send the correct amount of ETH to make send a message'
    );

    emit Spend(textMsg, recipient);
    messagesSentCount += 1;
    return true;
  }

  function setTxtPrices(uint _txtPriceUSD) external ownerOnly() {
    (int price,) = getLatestPrice();
    uint ethPriceUSD = uint(price);

    txtPriceEth = scale.mul(_txtPriceUSD).div(ethPriceUSD);
    txtPriceUSD = _txtPriceUSD;
  }

  function pollTxtPrices() external view returns(uint, uint, uint) {
    (int price,) = getLatestPrice();

    uint newTxtPriceEth = scale.mul(txtPriceUSD).div(uint(price));

    return (newTxtPriceEth, txtPriceUSD, decimals);
  }

  function totalBalance() external view returns(uint) {
    return payable(address(this)).balance;
  }

  function withdrawFunds() external ownerOnly() {
    msg.sender.transfer(this.totalBalance());
  }

  function destroy() external ownerOnly() {
    selfdestruct(owner);
  }

  function getLatestPrice() public view returns (int, uint) {
    (
      ,int price,,,
    ) = priceFeed.latestRoundData();

    return (price, decimals);
  }

  function uintToWei(uint unum) private pure returns(uint p) {
    return unum * (1 wei);
  }

  modifier ownerOnly() {
    require(msg.sender == owner, 'only owner can call this');
    _;
  }
}

truffle migrate --network mainnet --reset

  Replacing 'Migrations'
   ----------------------

Error:  *** Deployment Failed ***

"Migrations" could not deploy due to insufficient funds
   * Account:  0x16c8CF300eRa61f6d8e7S201AB7163FCc6660f1d
   * Balance:  297068575000000000 wei
   * Message:  sender doesn't have enough funds to send tx. The upfront cost is: 994313868000000000 and the sender's account only has: 297068575000000000
   * Try:
      + Using an adequately funded account
      + If you are using a local Geth node, verify that your node is synced.

Die Vorabkosten betragen 994313868000000000 Wei??

Das ist fast 1 Eth!


Antworten (2)

Erstens bin ich kein Experte auf diesem Gebiet und Sie können mich sehr gut als Anfänger sehen.

Diese Vorabkosten sind Gaspreis * Gas, das Sie senden, was in Ihrer Konfiguration festgelegt ist. Dies entspricht nicht unbedingt den tatsächlichen Kosten. Wichtig ist, wie viel Benzin Ihr Einsatz kosten wird. Der Rest des gesendeten Gases wird nicht verwendet. In Ihrem Fall sind Sie bereit zu zahlen: 211000000000 Wei pro Gaspreis. Sie geben auch an, dass Sie bereit sind, höchstens 4712388 Benzin auszugeben . Dann multipliziert es zu Beginn Ihres Einsatzes oder Probelaufs den Gaspreis, den Sie zahlen, mit der Menge an Gas, die Sie auszugeben bereit sind, und berechnet die "Vorabkosten". Wenn Sie diesen Betrag nicht auf Ihrem Konto haben, schlägt es fehl. Sie sollten entweder weniger für den Gaspreis bezahlen oder die Menge an Benzin, die Sie auszugeben bereit sind, reduzieren. Ich hoffe, es hilft.

Wie eine andere gültige Antwort hervorhob, betragen die eventuellen Gaskosten gas price* gas used. In Ihrem Fall beträgt Ihr Gaspreis 211000000000. Ihre Fragen geben nicht das erforderliche Gas an, sondern das maximal zulässige: 4712388.

Wenn wir nun davon ausgehen, dass Ihr Vertrag das gesamte zulässige Gas benötigt, betragen die Gaskosten: 4712388* 211000000000. Und das Ergebnis ist zufällig 994 313 868 000 000 000 – genau der Betrag, den Ihr Anbieter Ihnen gibt.

Also, ja, die Berechnungen stimmen. Und ja, das ist fast 1 Eth.

Der Vertrag sieht einfach aus, importiert jedoch einige andere Verträge, die nicht einfach sind.