Enviar una transacción con valor al contrato fallido

Estoy usando Ropsten Testnet y Remix.

¿Hay un error obvio en este código? ¿Por qué no acepta eth.

función () público a pagar { comprar (); }

function buy () payable public whenNotPaused beforeDeadline afterStartTime saleNotClosed {
    require(msg.value >= minContribution);

    // Update the sender's balance of wei contributed and the amount raised
    uint amount = msg.value;
    uint currentBalance = balanceOf[msg.sender];
    balanceOf[msg.sender] = currentBalance.add(amount);
    amountRaised = amountRaised.add(amount);

    // Compute the number of tokens to be rewarded to the sender
    // Note: it's important for this calculation that both wei
    // and PDT have the same number of decimal places (18)
    uint numTokens = amount.mul(rate);

    // Transfer the tokens from the crowdsale supply to the sender
    if (tokenReward.transferFrom(tokenReward.owner(), msg.sender, numTokens)) {
        FundTransfer(msg.sender, amount, true);
        // Check if the funding goal or cap have been reached
        // TODO check impact on gas cost
        checkFundingGoal();
        checkFundingCap();
    }
    else {
        revert();
    }
}

El contrato Crowdsale tiene una asignación. El límite de gas se ha aumentado de muchas maneras. ¡Advertencia de mi monedero ether!ingrese la descripción de la imagen aquí

El código completo está aquí: https://ropsten.etherscan.io/address/0x500c3ff2c1a561cd0fda1cf0c77fe0d17af5fda5

¿Qué me estoy perdiendo aquí?. Gracias de antemano por su respuesta. La última pregunta quedó sin respuesta, ¡así que vuelvo a preguntar!

Respuestas (2)

la función de reserva no puede ejecutar su función de compra () ya que solo tiene un estipendio de 2300 de gasolina. check ¿Cuánto cálculo se puede hacer en una función de respaldo?

así que elimínelo de la función de respaldo y llámelo directamente

function () payable public {  }

function buy () payable public whenNotPaused beforeDeadline afterStartTime saleNotClosed {
    require(msg.value >= minContribution);

    // Update the sender's balance of wei contributed and the amount raised
    uint amount = msg.value;
    uint currentBalance = balanceOf[msg.sender];
    balanceOf[msg.sender] = currentBalance.add(amount);
    amountRaised = amountRaised.add(amount);

    // Compute the number of tokens to be rewarded to the sender
    // Note: it's important for this calculation that both wei
    // and PDT have the same number of decimal places (18)
    uint numTokens = amount.mul(rate);

    // Transfer the tokens from the crowdsale supply to the sender
    if (tokenReward.transferFrom(tokenReward.owner(), msg.sender, numTokens)) {
        FundTransfer(msg.sender, amount, true);
        // Check if the funding goal or cap have been reached
        // TODO check impact on gas cost
        checkFundingGoal();
        checkFundingCap();
    }
    else {
        revert();
    }
}
Gracias por responder. Thorkil Værge cómo corregir esto. no soy programador Sin if (tokenReward.transferFrom(tokenReward.owner(), msg.sender, numTokens)) { , funciona bien. Simplemente no estoy seguro de cuándo eliminaré estas líneas, podré distribuir tokens. Badr Bellaj: cómo hacer que esta función alternativa sea más económica. ¿Qué debo eliminar?
Badr Bellaj, gracias por la corrección pero esto me da error en Remix
@Robert ahora debería estar bien. no olvides aceptar la respuesta si crees que es útil
Badr Bellaj Tenías razón. ¡Obras!

La llamada de función que está fallando es una llamada a este método:

function setTokenOffering(address offeringAddr, uint256 amountForSale) external onlyOwner onlyTokenOfferingAddrNotSet {
        require(!transferEnabled);

        uint256 amount = (amountForSale == 0) ? TokenAllowance : amountForSale;
        require(amount <= TokenAllowance);

        approve(offeringAddr, amount);
        tokenAllowanceAddr = offeringAddr;

    }

Ya ha llamado a la enableTransferfunción que se establece transferEnableden verdadero. Entonces, la primera línea del método anterior require(!transferEnabled);fallará y la ejecución se detendrá.