We used to deploy our smart contracts with Hardhat, but after spending around 250$ (for each deployment) we needed to debug that using remix.ethereum.org.
We have a pretty basic ERC 721 contract for our NFTs :
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
import "@manifoldxyz/creator-core-solidity/contracts/ERC721Creator.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "hardhat/console.sol";
contract MyContract is ERC721Creator {
// contractAddress
string private contractAddress;
// baseURI
string public baseURI;
constructor(string memory name, string memory symbol, string memory uri_) ERC721Creator(name, symbol) {
contractAddress = toString(address(this));
baseURI = string(abi.encodePacked(uri_, contractAddress, '/'));
}
function toString(bytes memory data) public pure returns(string memory) {
bytes memory alphabet = "0123456789abcdef";
bytes memory str = new bytes(2 + data.length * 2);
str[0] = "0";
str[1] = "x";
for (uint i = 0; i < data.length; i++) {
str[2+i*2] = alphabet[uint(uint8(data[i] >> 4))];
str[3+i*2] = alphabet[uint(uint8(data[i] & 0x0f))];
}
return string(str);
}
function toString(address account) public pure returns(string memory) {
return toString(abi.encodePacked(account));
}
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
require(_exists(tokenId), "Nonexistent token");
return bytes(baseURI).length != 0 ? string(abi.encodePacked(baseURI, Strings.toString(tokenId))) : '';
}
}
We choose to deploy the contract using Injected Provider MetaMask with ETH in our wallet.
When clicking on “transact”, a modal appears with a first error message about Gas estimation failed :
If we choose to send transaction, the MetaMask’s modal opens and the total transaction cost is more than 600$ !
So, we choose to decrease the gas limit in deploy remix.ethereum.org configuration.
We set it to 0100000.
When the MetaMask’s modal opens, costs seems to be correct with costs equal to 20$.
But after confirming the transaction, we got the following error in console :
Returned error: {“jsonrpc”:“2.0”,“error”:“[ethjs-query] while formatting outputs from RPC ‘{"value":{"code":-32000,"message":"intrinsic gas too low"}}’”,“id”:5317042078702854}
What’s happening ?
How to deploy a contract without paying high costs ?
Thanks