my smart contract cause error : out of gas error

my smart contract cause error : out of gas error

我的 solidity 代码有问题。 我认为,account.transfer

上的问题原因

我正在使用 ganache、remix、metamask、web3

这是我的 solidity 代码。

`pragma solidity ^0.4.25;
contract test{
    address fire_account=0x6F3c5e42c340736eEa9a1C362592Bef9Ba2E5561;
    mapping(string => uint) fire_record;
    function fireDonation(string contributorName) payable{
        fire_account.transfer(msg.value);
        fire_balance+=msg.value;
        fire_contributor.push(contributorName);
    }
}`

和web3.js代码

var Courses;
async function init(){
    web3 = await new Web3(new Web3.providers.HttpProvider("http://localhost:7545"));
    web3.eth.defaultAccount = web3.eth.accounts[2];
    console.log("Default account is ",web3.eth.accounts[2]);
    //Change the ABI here
    var CoursesContract = web3.eth.contract(/*skip*/);
    //Replace Deployed Smartcontract Address here
    var contractaddress = "0x9b95f972feaad42f2023246112f450c56d8921ae";
    Courses = CoursesContract.at(contractaddress);
}
init();
function fireDonate(){
    var amount=parseInt(document.getElementById('amount').value);
    console.log(amount);
    Courses.fireDonation(document.getElementById('contributor').value, {from: web3.eth.accounts[2], value: amount});
}

你能告诉我解决方案还是 link? 我找不到 links..

您的智能合约似乎需要比默认金额更多的 gas(费用)来执行。您必须增加 gasLimit 和 gasPrice 的默认值。您可以像这样用十六进制指定它们。

Courses.fireDonation(document.getElementById('contributor').value, {from: web3.eth.accounts[2], value: amount, gasLimit: '0x27100', gasPrice: '0x09184e72a00'});

您可能需要更改确切的值才能查看适合您的用例的值。