Burn in one contract and mint in other

Hi,

There is an option to burn tokens from one contract and in same function to mint in another contract?
I try something like that, but not work:

pragma solidity ^0.8.10;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol";
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/utils/Counters.sol";


contract VrsCoin is  ERC20  {

  mapping(address => uint) public userLevel;
  constructor() ERC20("vrsCoin", "VRS") {
        _mint(msg.sender, 1000000 * 10 ** decimals());
    }
    function makeBurn(uint256 amount) public {
      _burn(msg.sender, amount);
      incrementLevel();
    }
    function incrementLevel() internal {
      userLevel[msg.sender]++;
    }
    function getMyLevel() public view returns(uint){
      return userLevel[msg.sender];
    }
    function getAddrLevel(address addr) public view returns(uint){
      return userLevel[addr];
    }
    function burnToMint() public view returns(uint) {
      _burn(msg.sender,1000000);
      VrsToken vt;
      vt.safeMint(msg.sender);
    }
}

contract VrsToken is ERC721, Ownable {
    using Counters for Counters.Counter;

    Counters.Counter private _tokenIdCounter;

    constructor() ERC721("vrsToken", "VTK") {}


    function safeMint(address to) public onlyOwner {
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
    }
}

Your view function won’t be able to transact on an ERC20 burn function as it updates the state of the contract, which isn’t possible via a view.

Example Alternative burnToMint() function:

function burnToMint(uint amount) external onlyOwner {

// enter (optional) requirement(s) //
_burn(_msgSender(), amount);
tokenB.mint(msg.sender, amount);
// emit (optional) event //

}

Consider the following (since I dunno the full context of your specific implementation):

  1. Restrict the function to authorized accounts.
  2. Ensure the contract has permission to mint tokens (check the contract “token”).
  3. Ensure tokenB has a mint function and is defined somewhere in the contract as a token with an interface that allows for a mint that takes in the assumed parameters (account, amount).

These are my immediate thoughts. Back to my bath meow :sparkles: