Getting the following error: revert The transaction has been reverted to the initial state. Note: The called function should be payable if you send value and the value you send should be less than your current balance. Debug the transaction to get more information.

Also I am getting this warning: Gas requirement of function Unknown.listUser is infinite: If the gas requirement of a function is higher than the block gas limit, it cannot be executed. Please avoid loops in your functions or actions that modify large areas of storage (this includes clearing or copying arrays in storage) Pos: 39:4:.

Should I not use string and use bytes32? Is it bad to use string??

Code is given below.

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.18;

contract Unknown {
    struct User{
        string name;
        address walletAddress;
        uint256 phoneNumber;
        uint256 addressCount;
        uint256 productOnSaleCount;

    User[] public allUsers;
    Products[] public allProducts;

    struct Products{
        string name;
        string description;
        uint256 price;
        string[] images;
        uint256 imagesCount;

    struct UserAddress{
        string name;
        string streetName;
        string city;
        string state;
        string country;
        uint256 pincode;
    mapping(address => User) public walletAddressToUser;
    mapping(address => UserAddress[]) public walletAddressToUserAddresses;
    mapping(address => Products[]) walletAddressToUserBoughtProducts;
    mapping(address => Products[]) walletAddressToUserOnSaleProducts;
    mapping(address => Products[]) ProductsInCard;

    function listUser(string memory _name, uint256 _phoneNumber, string memory _addrName,string memory _streetName, string memory _city, string memory _state, string memory _country, uint256 _pincode ) public {
        require(walletAddressToUser[msg.sender].walletAddress == address(0), "User already Listed");
        User storage user = walletAddressToUser[msg.sender];
        user.name = _name;
        user.phoneNumber= _phoneNumber;
        user.walletAddress = msg.sender;
        walletAddressToUser[msg.sender] = user;
        UserAddress storage userAddress = walletAddressToUserAddresses[msg.sender][walletAddressToUser[msg.sender].addressCount];
        userAddress.name = _addrName;
        userAddress.streetName = _streetName;
        userAddress.city = _city;
        userAddress.state = _state;
        userAddress.country = _country;
        userAddress.pincode = _pincode;

    function listProductOnSale(string memory _name, string memory _decription, uint256 _price, string memory _imageUrl) public {
        Products storage product = walletAddressToUserOnSaleProducts[msg.sender][walletAddressToUser[msg.sender].productOnSaleCount];
        product.name = _name;
        product.description = _decription;
        product.price = _price;
        product.images[product.imagesCount] = _imageUrl;


1 Answer 1


From the error message, I would guess that you are trying to call the function listUser with a non-zero value in the transaction. The function does not require any ether to be sent, so value should be 0. That should fix it.

If you do want to send ether to a contract when executing a function, the function needs to be specified as payable, which simply means to define your function as:

function listUser(<arguments here>) public payable {
    ... function logig here ...

But as I said, in the way the function is defined, it does not require any ether to be sent, so you should simply execute the transaction with value=0.

  • I am executing at value=0 but still getting that error. Jun 7, 2023 at 15:03
  • can you provide more details on the arguments of the call you are making? what arguments are you passing to the function for instance Jun 7, 2023 at 20:53
  • I am using remix IDE and deployed it there and for calling the function I simply entered the parameters as mentioned in the function and then clicked on transact to execute it and then the error showed in the terminal of remix IDE given in the description of the question about the transaction being reverted. Jun 8, 2023 at 10:04
  • But your function requires a number of arguments in order to accept your transaction. What arguments did you put? Otherwise you cannot execute that transaction Jun 8, 2023 at 14:55
  • Yes, I gave all the arguments to the function from name to pincode. Jun 8, 2023 at 16:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.