Hi everyone.
I am new in solidity. I just want to create a ERC721 contract to mint by ERC20 token. I written the contract like this:
function creatCard() public payable returns (uint) {
require(msg.value == 0.01 ether);
cardId.increment();
uint _newCardId = cardId.current();
_safeMint(msg.sender, _newCardId);
idToOwner[_newCardId] = msg.sender;
idToCard[_newCardId] = Cards(_newCardId,_getRandom(_newCardId, 100) + 1,_getRandom(_newCardId, 9),1,0);
return _newCardId;
}
on the front end, I written by javascript like this:
async function mint() {
var data = await myContract.methods.creatCard().send({
from:myAccount,
value:0.01*10**18,
gas: 2500000
})
.on("transactionHash", function () {
console.log("Hash");
})
.on("receipt", function () {
console.log("Receipt");
})
.on("confirmation", function () {
console.log("Confirmed");
})
.on("error", async function () {
console.log("Error");
});
console.log(data);
}
I does work by paying 0.01 ether to mint a new card.
But I want to pay other token instead, such as BUSD or ERC20 I create, not ETH,
so, how can I update my code?