The essence of the problem
A window opens in Meta mask about paying for gas. I can click continue, but I can't wait for the positive completion of the transaction once - an error always
occurs{"blockHash":"0x33e1cd0a7c540d9cb08319bfdeae2ab87bf7a81f1daec361298f9735260c4b93", "blockNumber":"9968588", "cumulativeGasUsed":"1339077", "effectiveGasPrice":"2500000010", "from":"0x****************", "gasUsed":"21069", "logs"[], "logsBloom":"0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"status":"0", "to":"0x4f37382283719cf4151e27412c60472303fd158f", "transactionHash":"0x375c55a6e8f29eddd454e3a7bbf0af4245d3c44cfccea87bade47441c1941857", "transactionIndex":"1","type":"2"}"
I'm trying using Next.js write an interface for a smart contract, which is shown below:
contract CampaignFactory {
address payable[] public deployedCampaigns;
function createCampaign(uint minimum) public {
address newCampaign = address(new Campaign(minimum, msg.sender));
deployedCampaigns.push(payable(newCampaign));
}
function CreateNewIdenticalCampaign() public {
address newCampaign = address(new Campaign(100, msg.sender));
deployedCampaigns.push(payable(newCampaign));
}
function getDeployedCampaigns()
public
view
returns (address payable[] memory)
{
return deployedCampaigns;
}
}
The get (getDeployedCampaigns) method works very well in the Remix Ethereum IDE and in my application.
But there are troubles with post methods. I can immediately say with confidence that the post methods are not broken, since everything in them works perfectly, but only in the Remix. I assume that the code in my application is written incorrectly in the **.js file:
const accounts = await web3.eth.getAccounts();
const minimumWei = web3.utils.toWei(
this.state.minimumContribution,
"ether"
);
const gas = await factory.methods
.createCampaign(minimumWei)
.estimateGas({ from: accounts[0] });
await factory.methods
.createCampaign(minimumWei)
.send({
from: accounts[0],
gas: 10000000, //web3.utils.toHex(gas),
gasPrice: web3.utils.toWei("0.0001", "gwei"),
})
.on("transactionHash", function (hash) {
console.log("Transaction send, hash: " + hash);
})
.on("receipt", function (receipt) {
console.log("Done, : " + receipt.blockNumber);
})
.on("error", function (error) {
console.error("Error: " + error.message);
});
I tried not to specify the gas, gas Price properties, but nothing helps.
So good! I found the answer to the question, it turns out that in 2023 you need to program differently than in 2019 in web3 - you also need to send the method ABI, here is a working version of the code: