# Fail with error 'ERC1155: insufficient balance for transfer'

**URL:** <https://forum.openzeppelin.com/t/fail-with-error-erc1155-insufficient-balance-for-transfer/27054>\
**Category:** Smart Contracts\
**Tags:** erc1155\
**Created:** [March 31, 2022, 12:40pm UTC](https://forum.openzeppelin.com/t/fail-with-error-erc1155-insufficient-balance-for-transfer/27054 "2022-03-31T12:40:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ricky](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@ricky](https://forum.openzeppelin.com/u/ricky)\
**Post date:** [March 31, 2022, 12:40pm UTC](https://forum.openzeppelin.com/t/fail-with-error-erc1155-insufficient-balance-for-transfer/27054/1 "2022-03-31T12:40:42Z")

</div>

Hey Everyone 🙂 Testing out a purchase function on my smart contract and running into this ERC1155 error when attempting to purchase an NFT for sale. Contract has been deployed via Remix on Ropsten network with Gas Limit of 300000000 and 1 ETH of Value. Solidity function will be pasted below but I'm thinking this is not a code error?

```auto
    function createMarketSale(
        address nftContract,
        uint256 itemId,
        uint256 amount,
        bytes memory data
        ) public payable nonReentrant {
            uint price = idToMarketItem[itemId].price;
            uint tokenId = idToMarketItem[itemId].tokenId;
            bool sold = idToMarketItem[itemId].sold;
            require(msg.value == price, "Please submit the asking price in order to complete the purchase");
            require(sold != true, "This Sale has alredy finnished");
            emit MarketItemSold(
                itemId,
                msg.sender
                );

            idToMarketItem[itemId].seller.transfer(msg.value);
            IERC1155(nftContract).safeTransferFrom(msg.sender, address(this), tokenId, amount, data);
            idToMarketItem[itemId].owner = payable(msg.sender);
            _itemsSold.increment();
            idToMarketItem[itemId].sold = true;
        }

```

 ![image](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/b/b4f339f2eec8fee03a90fe5e29a314bd671849df.png)

I'm not entirely sure what funds I need in order to complete. The wallet I am making this transaction with has more than enough ETH to make this purchase. Any help would be greatly appreciated 🙂

Transaction Hash: 0xa0680bd6625b8a898e27b76dc20b51950b04ddfc3a5498b8102095292e23c174

---

<div class="post-metadata">

**Author:** ![asato](https://avatars.discourse-cdn.com/v4/letter/a/dfb087/32.png) [@asato](https://forum.openzeppelin.com/u/asato)\
**Post date:** [March 31, 2022, 1:14pm UTC](https://forum.openzeppelin.com/t/fail-with-error-erc1155-insufficient-balance-for-transfer/27054/2 "2022-03-31T13:14:00Z")

</div>

It's the contract bug.  
Did you implement the test script with javascript?

---

<div class="post-metadata">

**Author:** ![ricky](https://avatars.discourse-cdn.com/v4/letter/r/439d5e/32.png) [@ricky](https://forum.openzeppelin.com/u/ricky)\
**Post date:** [March 31, 2022, 1:40pm UTC](https://forum.openzeppelin.com/t/fail-with-error-erc1155-insufficient-balance-for-transfer/27054/3 "2022-03-31T13:40:16Z")

</div>

So how I am executing the function is as follows:

On my Frontend I have a page that shows all NFT's currently for sale. Users can view an NFT and when they click purchase I fire off a purchase function which I'll paste below.

```auto
  async function purchase() {
    debugger
    setLoading(true);
    const tokenDetails = getMarketItem(nftToBuy);
    const itemID = tokenDetails.itemId;
    const tokenPrice = tokenDetails.price;
    const ops = {
      contractAddress: marketAddress,
      functionName: purchaseItemFunction,
      abi: contractABIJson,
      params: {
        nftContract: nftToBuy.token_address,
        itemId: itemID,
        amount: nftToBuy.amount,
        data: [],
      },
      msgValue: tokenPrice,
    };
    debugger;
    await contractProcessor.fetch({
      params: ops,
      onSuccess: () => {
        console.log("success");
        setLoading(false);
        setVisibility(false);
        updateSoldMarketItem();
        succPurchase();
      },
      onError: (error) => {
        setLoading(false);
        failPurchase();
      },
    });
  }

```

The getMarketItem essentially just retrieves the nft data that is being stored on Moralis, I then set that itemID as well as get the price.

```auto
Market Address is 0x83cDeE9f50c40E74704200993c529B4AB6959354
functionName: "createMarketSale"
ABI which I get from Remix.

params: 
nftContract: "0x309f24be235e3be133b617e126a16e171b916331"
itemID: I retrieve from Moralis
amount: is generally 1
data: []

```

(ContractProcessor is using useWeb3ExecuteFunction())

I have tested another function from the smart contract on my Frontend (Listing NFT for sale) and that works without error.

I hope that gives a bit more insight 🙂
