# Contract that must exchange one 3rd party token to its own

**URL:** <https://forum.openzeppelin.com/t/contract-that-must-exchange-one-3rd-party-token-to-its-own/24043>\
**Category:** Smart Contracts\
**Tags:** erc20\
**Created:** [February 4, 2022, 4:49pm UTC](https://forum.openzeppelin.com/t/contract-that-must-exchange-one-3rd-party-token-to-its-own/24043 "2022-02-04T16:49:27Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![adminoid](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.openzeppelin.com/adminoid/32/12426_2.png) [@adminoid](https://forum.openzeppelin.com/u/adminoid)\
**Post date:** [February 4, 2022, 4:49pm UTC](https://forum.openzeppelin.com/t/contract-that-must-exchange-one-3rd-party-token-to-its-own/24043/1 "2022-02-04T16:49:28Z")

</div>

I have a smart contract for exchange USDT to QUE token with rate 1:1

```auto
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";

contract Question is ERC20 {
    address USDTAddress;
    address BoxAddress;

    constructor(address _USDTAddress) ERC20("Question", "QUE") {
        USDTAddress = _USDTAddress;
        BoxAddress = msg.sender;
    }

    function depositUSDT(uint _tokenAmount) public payable {
        ERC20 USDTToken = ERC20(USDTAddress);
        USDTToken.transferFrom(msg.sender, BoxAddress, _tokenAmount);
        _mint(msg.sender, _tokenAmount);
    }
}

```

And I wrote a test:

```auto
const { expect } = require("chai")
const { ethers, waffle } = require('hardhat')
const { deployContract } = waffle

// contracts
const QJson = require('../artifacts/contracts/Question.sol/Question.json')
const MockUSDT = require('../artifacts/contracts/mocks/mockUSDT.sol/MockUSDT.json')

describe('Question.sol', _ => {
  it('Deposit USDT with Question.sol', async () => {
    const [walletUSDT, walletMatrix] = await ethers.getSigners()

    const tokenUSDT = await deployContract(walletUSDT, MockUSDT)

    // I guess that walletMatrix is a BoxAddress in Question.sol
    // and tokenUSDT.address is a _USDTAddress in a constructor of Question.sol
    const tokenMatrix = await deployContract(walletMatrix, QJson, [
      tokenUSDT.address,
    ])

    // there I put deposit to walletMatrix.address
    await tokenUSDT.connect(walletUSDT).transfer(walletMatrix.address, 11)
    let balance = await tokenUSDT.balanceOf(walletMatrix.address)
    expect(balance).to.equal(11) // ok

    await tokenUSDT.approve(walletMatrix.address, 900)
    // after line below I've got the error:
    await tokenMatrix.connect(walletMatrix).depositUSDT(900)
    // ERC20: transfer amount exceeds balance

    // What's wrong?

    // let matrixBalance = await tokenMatrix.balanceOf(walletMatrix.address)
    // expect(matrixBalance).to.equal(amount2)
  }).timeout(20000)
})

```

What I do wrong? Maybe I don't understand correctly values in my .sol and .js files?
