How to write an additional contract that can call test coins to buy test NFTs?

This is my test coin contract

 contract Xchain is ERC20 {

constructor() ERC20("Xuuu", "XXX") {
     _mint(msg.sender, 100000000 * 10 ** decimals());
    function transfer(address to, uint256 amount) public virtual override returns (bool) {
    address owner = _msgSender();
    _transfer(owner, to, amount);
    return true;


Here is my test NFT contract

contract nfts is ERC721, ERC721URIStorage, ERC721Burnable, Ownable {
using Counters for Counters.Counter;

Counters.Counter private _tokenIdCounter;

constructor() ERC721("nfts", "nf") {}

function safeMint(address to, string memory uri) public onlyOwner {
    uint256 tokenId = _tokenIdCounter.current();
    _safeMint(to, tokenId);
    _setTokenURI(tokenId, uri);

// The following functions are overrides required by Solidity.

function _burn(uint256 tokenId) internal override(ERC721, ERC721URIStorage) {

function tokenURI(uint256 tokenId)
    override(ERC721, ERC721URIStorage)
    returns (string memory)
    return super.tokenURI(tokenId);

My problem is to write a new contract, the caller of this contract can deduct the amount of the corresponding test coins and then mint a test nft。

Hi, welcome to the community! :wave:

I think you can do like so:

// !!! Only for test !!!
function YOUR_FUNCTION() {
    TEST_TOKEN.transferFrom(msg.sender, address(this), AMOUNT);
    NFT.safeMint(msg.sender, URI);