# MetaMask internal JSON-rpc error when calling smart contract

**URL:** <https://forum.openzeppelin.com/t/metamask-internal-json-rpc-error-when-calling-smart-contract/15027>\
**Category:** Smart Contracts\
**Created:** [September 3, 2021, 11:56pm UTC](https://forum.openzeppelin.com/t/metamask-internal-json-rpc-error-when-calling-smart-contract/15027 "2021-09-03T23:56:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![meditation](https://avatars.discourse-cdn.com/v4/letter/m/a587f6/32.png) [@meditation](https://forum.openzeppelin.com/u/meditation)\
**Post date:** [September 3, 2021, 11:56pm UTC](https://forum.openzeppelin.com/t/metamask-internal-json-rpc-error-when-calling-smart-contract/15027/1 "2021-09-03T23:56:09Z")

</div>

Hi there,

We are building a escrow service on ethereum, and more specifically its about escrow on ERC20 tokens. First it deposits funds into a smart contract, and then release funds from the smart contract.

The problem happens when I do two escrows in a row, and the depositing part are all working fine. However, when I tried to invoke the MetaMask to call the smart contract to do two release funds in a row, got this rpc error.

 ![Screen Shot 2021-09-03 at 10.48.45 PM](https://us1.discourse-cdn.com/flex022/uploads/zeppelin/original/2X/8/8eeb276e8b31b044c284d86e2a616cca54dff30d.jpeg)

The smart contract code is as like this:

```auto
function releaseEscrow(uint _orderId) external onlySeller(_orderId){ 
         Escrow memory _escrow = escrows[_orderId];     
        require(escrows[_orderId].status == EscrowStatus.Funded,"USDT has not been deposited");         
        _escrow.status = EscrowStatus.TokenApproved;
        
        uint256 _totalFees = _escrow.sellerfee + _escrow.buyerfee + _escrow.additionalGasFees;
        feesAvailable += _totalFees;
        
        // here we tell the curreny that the buyer can ONLY have 'value' funds.
        tokenccy.safeApprove(_escrow.buyer,(_escrow.value - _totalFees));
        
        require(_escrow.status == EscrowStatus.TokenApproved,"USDT has not been approved!");
        _escrow.status = EscrowStatus.Completed;
        
        tokenccy.safeTransfer( _escrow.buyer, (_escrow.value - _totalFees) );
        delete escrows[_orderId];
        emit EscrowComplete(_orderId, _escrow);
    }

```

The actual deposit solidy code is as following:

```auto
function createEscrow(uint _orderId, address payable _buyer, address payable _seller, uint _value, uint _sellerfee, uint _buyerfee) external onlyOwner {
        require(escrows[_orderId].status == EscrowStatus.Unknown, "Escrow already exists");
        
        //Transfer USDT to contract after escrow creation
        require( tokenccy.allowance( _seller, address(this)) >= (_value),"Seller needs to approve funds to Escrow first !!");
        
        tokenccy.safeTransferFrom(_seller, address(this) , (_value) );
        Escrow memory _escrow = Escrow(_buyer, _seller, _value, /*gas*/0, _sellerfee, _buyerfee, EscrowStatus.Unknown); 
         _escrow.status = EscrowStatus.Funded;
        escrows[_orderId] = _escrow;
        tokenccy.safeApprove(_escrow.buyer,0); // reset any allowances

        emit EscrowDeposit(_orderId, _escrow);
     }

```

Could someone point me to the right direction?

Do we need to safeApprove each transaction before transfer?

Thanks in advance.
