Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

234
Vistas
ERC721 contract using ERC20 token ignored in _safeMint

I am trying to perform a _safeMint in javascript, but the ERC20 token is ignored. Instead the set value is seen as the token of the BSC testnet, aka BNB.

The use of the ERC20 token by the contract is approved for the users Wallet.

So instead of saying to the buyer that he/she has to pay 1 USDT & some gas fee (BNB), it says it wants to withdraw the amount of "1+gas fee" BNB.

I'm scratching my head about this issue...

My javascript code to perform _safeMint

async function request_accounts() {
            console.log ("before await 1")
            provider = await get_provider();
            await provider.send("eth_requestAccounts", []);
            const signer = provider.getSigner();
            
            return signer;
        }

async function connect_contract(){
            signer = await request_accounts();
            contract = new ethers.Contract(contractAddress, abi, signer);
            
            return contract;
        }
     
async function buy_NFT() {
                console.log("before_buy_NFT");
                contract = await connect_contract();
                var test2 = await contract.safeMint("Wallet_address", "teststring", {value: ethers.utils.parseEther("1"), gasLimit: 50000,nonce: undefined});
                console.log("after_buy_NFT");
            }

I have following Solidity code for my smart contract:

pragma solidity ^0.8.15;

import "@openzeppelin/contracts@4.6.0/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts@4.6.0/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts@4.6.0/token/ERC721/extensions/ERC721URIStorage.sol";
import "@openzeppelin/contracts@4.6.0/access/Ownable.sol";
import "@openzeppelin/contracts@4.6.0/utils/Counters.sol";
import "@openzeppelin/contracts@4.6.0/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts@4.6.0/utils/cryptography/draft-EIP712.sol";

contract test is ERC721, EIP712, ERC721URIStorage, Ownable {
    using Counters for Counters.Counter;
    Counters.Counter private _tokenIdCounter;
    uint256 rate = 1 * 10 **18; // 1 USDT
    
IERC20 public tokenAddress;

    constructor(address _tokenAddress) ERC721("test", "test") EIP712(SIGNING_DOMAIN, SIGNATURE_VERSION) {
        tokenAddress = IERC20(_tokenAddress);
    }

    function safeMint(address to, string memory uri) payable public  {
        require(msg.value >= rate, "Please increase your USDT amount. Please check the ticket price");
        tokenAddress.transferFrom(msg.sender, address(this), rate);
        uint256 tokenId = _tokenIdCounter.current();
        _tokenIdCounter.increment();
        _safeMint(to, tokenId);
        _setTokenURI(tokenId, uri); 
    }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda