Cyfrin / foundry-nft-cu

22 stars 26 forks source link

Failed to send Transaction - Intrinsic Gas too high #35

Closed tamermint closed 5 months ago

tamermint commented 5 months ago

Hi all,

I am trying to deploy the MoodNft named as evolutionNft.sol - I made a tweak - I am using a different SVG image - but the logic is the same. However, when I am deploying it on anvil I get this error :

make deployEvolution 
[⠊] Compiling...
No files changed, compilation skipped
EIP-3855 is not supported in one or more of the RPCs used.
Unsupported Chain IDs: 31337.
Contracts deployed with a Solidity version equal or higher than 0.8.20 might not work properly.
For more information, please see https://eips.ethereum.org/EIPS/eip-3855
Script ran successfully.

== Return ==
0: contract EvolutionNft 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512

## Setting up 1 EVM.

==========================

Chain 31337

Estimated gas price: 1.750351068 gwei

Estimated total gas used for script: 60931837

Estimated amount required: 0.106652105968151916 ETH

==========================
##
Sending transactions [0 - 0].

Transactions saved to: /Users/vivekmitra/Desktop/Learn2Code/web3code/Foundry/foundry-nfts-f24/broadcast/DeployEvolutionNft.s.sol/31337/run-latest.json

Sensitive values saved to: /Users/vivekmitra/Desktop/Learn2Code/web3code/Foundry/foundry-nfts-f24/cache/DeployEvolutionNft.s.sol/31337/run-latest.json

Error: 
Failed to send transaction

Context:
- server returned an error response: error code -32000: intrinsic gas too high -- tx.gas_limit > env.block.gas_limit
make: *** [deployEvolution] Error 1

I am using freshly imported anvil account in metamask and I cleared the nonce and activity through metamask but I still am facing the issue.

I did move ahead and used cast on the contract address returned above :

cast send 0x5fbdb2315678afecb367f032d93f642f64180aa3 "min
tNft()" --private-key 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80

blockHash               0xba9b19680e045daffab3ab99d7ae9729261c70349e84f6b9fbc6532bca599306
blockNumber             1
contractAddress         
cumulativeGasUsed       21064
effectiveGasPrice       1000000000
from                    0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266
gasUsed                 21064
logs                    []
logsBloom               0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
root                    0x8e22fef8eadfc5abb886fffb6c7b4b1d4f3510246984e78badd7f43de8a204ab
status                  1 (success)
transactionHash         0xb9a3b955f03ecfd3cb573409ac2219ced7bb51315cf226914241f27ea73bbdee
transactionIndex        0
type                    2
blobGasPrice            1
blobGasUsed             
to                      0x5FbDB2315678afecb367f032d93F642f64180aa3

But in metamask, it doesn't let me import token and it tells me I am not the owner :

Screenshot 2024-06-18 at 18 56 54

My deploy script :

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.19;

import {Script, console} from "forge-std/Script.sol";
import {EvolutionNft} from "../src/EvolutionNft.sol";
import {Base64} from "@openzeppelin/contracts/utils/Base64.sol";

contract DeployEvolutionNft is Script {
    function run() external returns (EvolutionNft) {
        string memory porcuSvg = vm.readFile("./img/porcuparus.svg");
        string memory charoSvg = vm.readFile("./img/charosaurus.svg");

        vm.startBroadcast();
        EvolutionNft evolutionNft = new EvolutionNft(
            svgToImageUri(porcuSvg),
            svgToImageUri(charoSvg)
        );
        vm.stopBroadcast();
        return evolutionNft;
    }

    //function to put in any svg and get the base64 encoded version
    function svgToImageUri(
        string memory svg
    ) public pure returns (string memory) {
        string memory baseUri = "data:image/svg+xml;base64,";
        string memory svgBase64Encoded = Base64.encode(
            bytes(string(abi.encodePacked(svg)))
        );
        return string(abi.encodePacked(baseUri, svgBase64Encoded));
    }
}

Can anyone please advice? Thanks in advance :)

tamermint commented 5 months ago

Also - I tried deploying on Sepolia - it failed because of high gas as well (I don't have 0.6 SepEth) :

 make deployEvolution ARGS="--network sepolia"
[⠒] Compiling...
No files changed, compilation skipped
Traces:
  [50158302] DeployEvolutionNft::run()
    ├─ [0] VM::envUint("PRIVATE_KEY") [staticcall]
    │   └─ ← [Return] <env var value>
    ├─ [0] VM::readFile("./img/porcuparus.svg") [staticcall]
    │   └─ ← [Return] <file>
    ├─ [0] VM::readFile("./img/charosaurus.svg") [staticcall]
    │   └─ ← [Return] <file>
    ├─ [0] VM::startBroadcast(<pk>)
    │   └─ ← [Return] 
    ├─ [45700028] → new EvolutionNft@0x1b1e8E7c8eb31acEEA360C064C65aa4D8CA27847
    │   └─ ← [Return] 5143 bytes of code
    ├─ [0] VM::stopBroadcast()
    │   └─ ← [Return] 
    └─ ← [Return] EvolutionNft: [0x1b1e8E7c8eb31acEEA360C064C65aa4D8CA27847]

Script ran successfully.

== Return ==
0: contract EvolutionNft 0x1b1e8E7c8eb31acEEA360C064C65aa4D8CA27847

## Setting up 1 EVM.
==========================
Simulated On-chain Traces:

  [45700028] → new EvolutionNft@0x1b1e8E7c8eb31acEEA360C064C65aa4D8CA27847
    └─ ← [Return] 5143 bytes of code

==========================

Chain 11155111

Estimated gas price: 11.05889522 gwei

Estimated total gas used for script: 60931837

Estimated amount required: 0.67383880094511914 ETH

==========================
##
Sending transactions [0 - 0].

Transactions saved to: /Users/vivekmitra/Desktop/Learn2Code/web3code/Foundry/foundry-nfts-f24/broadcast/DeployEvolutionNft.s.sol/11155111/run-latest.json

Sensitive values saved to: /Users/vivekmitra/Desktop/Learn2Code/web3code/Foundry/foundry-nfts-f24/cache/DeployEvolutionNft.s.sol/11155111/run-latest.json

Error: 
Failed to send transaction

Context:
- server returned an error response: error code -32000: max initcode size exceeded: code size 70085, limit 49152
make: *** [deployEvolution] Error 1
PatrickAlphaC commented 5 months ago

Your SVGs are too big to fit into one contract :)

You'll have to get creative if you want to keep them as SVGs! Otherwise, you can have them point to IPFS or something else.

tamermint commented 5 months ago

Thanks @PatrickAlphaC - so all I need to do is change this :

string memory porcuSvg = vm.readFile("./img/porcuparus.svg");
string memory charoSvg = vm.readFile("./img/charosaurus.svg");

to

string memory porcuSvg = ipfs://...
string memory charoSvg = ipfs://...

?

PatrickAlphaC commented 5 months ago

That should work! Since an IPFS link will be much smaller.