Share Dialog
Share Dialog
Subscribe to zinderud
Subscribe to zinderud
You can edit the mint function require the user to transfer certain ERC-20 tokens in your mint function. You can define a price for the ERC-721 tokens in terms of the ERC-20 token, and perform a transferFrom on the ERC-20 contract.
Of course, the user should have to approve the ERC-721 contract as a spender. The code could look something like this.
` contract MyNFT is ERC721 { address tokenAddress; uint256 price;
constructor(address _tokenAddress, uint256 _price) ERC721("MyNFT", "NFT") {
tokenAddress = _tokenAddress;
price = _price;
}
function safeMint(address to, uint256 tokenId) public {
ERC20(tokenAddress).transferFrom(msg.sender, address(this), price);
_safeMint(to, tokenId);
}
}`
You can edit the mint function require the user to transfer certain ERC-20 tokens in your mint function. You can define a price for the ERC-721 tokens in terms of the ERC-20 token, and perform a transferFrom on the ERC-20 contract.
Of course, the user should have to approve the ERC-721 contract as a spender. The code could look something like this.
` contract MyNFT is ERC721 { address tokenAddress; uint256 price;
constructor(address _tokenAddress, uint256 _price) ERC721("MyNFT", "NFT") {
tokenAddress = _tokenAddress;
price = _price;
}
function safeMint(address to, uint256 tokenId) public {
ERC20(tokenAddress).transferFrom(msg.sender, address(this), price);
_safeMint(to, tokenId);
}
}`
<100 subscribers
<100 subscribers
No activity yet