Steps:
I have deployed a smart contract on Polygon Mumbai Testnet.
Granted role.
Start drop.
Approved several token URI
But the issue is that I am not able to mint now.
This is the error:
transact to NativzKeyMinter.mint errored: Internal JSON-RPC error.
{
"code": 3,
"data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001654686520707269636520697320696e636f727265637400000000000000000000",
"message": "execution reverted: The price is incorrect"
Just search for require(PRICE_CONDITION,"The price is incorrect") inside your minting function of the smartcontract. Probably you are submiting zero value transaction, while the contract requires Matic tokens.
Related
For example, if a user hasn't approved a contract to spend the user's funds, and the user tries to conduct a transaction, the error from remix states that the user hasn't allowed the contract whereas the metamask error doesn't mention any helpful information. All the metamask error says is "Internal JSON-RPC error."
My question is how do I get those errors messages visible in remix in metamask when using a web library such as web3.js?
I have deployed a smart contract to the Ropsten Ethereum test network.
The source code is visible here : https://pastebin.com/yH327yzD
I have minted 1000 tokens to my address (external to the smart contract, this address is the owner of the smart contract).
I have sent these 1000 tokens to the smart contract, through Metamask.
Now I'd like to retrieve these 1000 tokens from the external address again (that is the owner of the smart contract).
When I try to call the "transfer()" function of the smart contract, the following error is shown :
Gas estimation errored with the following message (see below). The transaction execution will likely fail. Do you want to force sending?
execution reverted: ERC20: transfer amount exceeds balance { "originalError": { "code": 3, "data": "0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000002645524332303a207472616e7366657220616d6f756e7420657863656564732062616c616e63650000000000000000000000000000000000000000000000000000", "message": "execution reverted: ERC20: transfer amount exceeds balance" } }
What am I doing wrong ?
Thanks.
With Metamask, users have to manually import tokens to their account for these to show up in the Assets section. This is has a neat security feature as dust attack and other "spam" tokens are out of sight from the user. You wallet is usually full of spam as well.
Now I want to relay these user intentions (import of a token) to a custom dApp and filter the tokens according to what the user has imported on his Metamask.
i.e can you access the tokens user has imported to his Metamask and thus see the "whitelisted" contract addresses on users Metamask using the ehtereum or other API?
I have more or less read through the Metamask API docs but didn't find anything.
Only hint I found was in this article saying it cannot be done.
unfortunately we can not get all the tokens the wallet has access to, we need to know first the smart contract addresses.
To best of my knowledge it cannot be done, but what you can do is access the tokens that the user has in their wallet (Not the ones imported into metamask)
Using the Moralis Web3 SDK you can retrieve all token balances of a current user or specified address using:
const balances = await Moralis.Web3API.account.getTokenBalances({address: "any_address"});
And you get an object with the number of tokens and the array of token objects
Example:
[
{
"token_address": "0x2d30ca6f024dbc1307ac8a1a44ca27de6f797ec22ef20627a1307243b0ab7d09",
"name": "Kylin Network",
"symbol": "KYL",
"logo": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c.png",
"thumbnail": "https://cdn.moralis.io/eth/0x67b6d479c7bb412c54e03dca8e1bc6740ce6b99c_thumb.png",
"decimals": "18",
"balance": "123456789"
},
{other tokens}
]
To filter out the spam token you could iterate over the result and query the user allowance for each of the token contracts. We could suppose that the tokens with allowance != 0 are the token are not spam
I've cobbled together some code to send some tokens using web3.js 1.0.0-beta46 and then decided to try to send more token than I had in my wallet. to my great surprise the transaction send succeeded and I got a txid, but of course the transfer failed
here's the attempt (on Ropsten):
https://ropsten.etherscan.io/tx/0xaf2708dcc9b86b7cca0076e329a1e81fc28fdc4a97765b0a79544ec0685cfa69
now my question: how can I tell when the transfer succeeded? or for that matter how can I get the error message? etherscan merely indicates:
ERC-20 Token Transfer Error (Unable to locate Corresponding Transfer Event Logs), Check with Sender
The most simple and straightforward way would be to check the balances of sender and receiver before and after the transfer.
Now about the failed transfer, after reading the contract I noticed that in the event of insufficient funds you simple return false, which makes a valid transaction. What you should do is revert the transactions using require to make the checks. That way an invalid transaction will be reverted by the EVM which will be recognized by etherscan and show that the transaction failed.
This question is a little conceptual, so hopefully this picture will help clear up my misunderstanding.
Image there is a crowdsale smart contract deployed on address 0x2. A User at address 0x01 buys a token.
Here is my understanding of what happens:
The crowdsale contract (# address: 0x2) accepts ether from the user account (# address: 0x1)
The crowdsale contract stores 0x1 as having purchased a token (important: this information is stored in the smart contract #address 0x2)
Now my Question: If 0x1 is a user account (and not a smart contract) there is no code at address 0x1. I thought a user account just consisted of an address + ether associated with the address, how can it also store the fact that 0x1 owns an ERC20 token? For example, I can login to MetaMask and (before clicking the "add token" option) MetaMask can see that I have a token... how is this possible?
Every ERC20 contract has the following function:
function balanceOf(address _owner) public view returns (uint256 balance) {
return balances[_owner];
}
Your wallet just calls this function from the known token contracts with your address. Since it's a view function it doesn't cost any gas.
I recon most ERC20 token get added rather quickly to a wallet like Metamask or MEW. But if your balance doesn't automatically show, you can add the contract address manually (in MEW at least, not sure about Metamask) and it will show up afterwards.
In solidity there are two ways to get the address of the person who sent the transaction
tx.origin
msg.sender
In your example, in the method inside ERC20 Token.sol, the value tx.origin will be 0x1 and msg.sender will be 0x2
So to answer your question, how does the ERC20 token know about 0x2 is: it depends on how the token contract is written and whether it uses tx.origin or msg.sender. I would imagine it uses msg.sender, because that is the more prevalent one.
If it does use msg.sender you can still make the crowdsale contract work by first buying the tokens and then immediatelly transfering the tokens from the crowdsale contract to the caller.
For more information, refer to What's the difference between 'msg.sender' and 'tx.origin'?
how can it also store the fact that 0x1 owns an ERC20 token?
Token transfers, or transfers in accounting in general, are kept in a ledger. In this case, the ledger is ERC-20 smart contract that internally keeps balances who owns and what in its balances mapping. Or, the smart contract manage the storage (EVM SSTORE instructions) where the records of ownership are kept.
Note that some other blockchains, like Telos and EOS (and mayne Solana) might be opposite and there the storage is maintained on the user account (user account has associated RAM and tables for any token user owns).