[SOLVED] Amount Trouble ERC20 tranferring

Hi!
When I trying to transfer erc20 token, amount of tokens become sooo big

my code

async function tokenTransfer() {
    var value = document.getElementById("value").value;
    const contract = "0x04c747b40be4d535fc83d09939fb0f626f32800b";
    const myadress = "0x97B6E7647fba574Ca1E9B46eDe48DB7188160cE2";
    await Moralis.authenticate({ signingMessage: "Test Authenticate" });
    const web3 = await Moralis.enableWeb3();
    

    const options = {type: "erc20", 
                 amount: Moralis.Units.Token(value, "18").toString(), 
                 receiver: myadress,
                 contractAddress: contract}
let result = await Moralis.Web3.transfer(options)
}

12 1200000

What was the value read from that html element?

I entered the value 12 in the input field
it read the value as 12

<input type="number" placeholder="0" id="value"></input>

12

From that print screen it looks like it tries to make a native transfer and not an erc20 transfer

other options for ERC20 trasfer writed on my script

async function tokenTransfer() {
    var value = document.getElementById("value").value;
    const contract = "0x04c747b40be4d535fc83d09939fb0f626f32800b";
    const myadress = "0x97B6E7647fba574Ca1E9B46eDe48DB7188160cE2";
    await Moralis.authenticate({ signingMessage: "Test Authenticate" });
    const web3 = await Moralis.enableWeb3();
    

    const options = {type: "erc20", 
                 amount: Moralis.Units.Token(value, "18").toString(), 
                 receiver: myadress,
                 contractAddress: contract}
let result = await Moralis.Web3.transfer(options)
}

from html-input i get only token amount

If you send directly without converting it to wei I guess that you don’t get the right pop up in metamask either

what do i need to do to fix this?

I don’t know know now, you have latest version of Moralis SDK?
I’m not at computer now to test

This should be without web3, it should be Moralis.transfer directly

i replaced this with Moralis.transfer(options) but the amount is still very large
i have this version of Moralis and Web 3

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/web3.min.js"></script>
<script src="https://unpkg.com/moralis/dist/moralis.js"></script>

That seems ok for the sdk version

This is the example from documentation, seems similar to what you have


// sending 0.5 tokens with 18 decimals
const options = {type: "erc20", 
                 amount: Moralis.Units.Token("0.5", "18"), 
                 receiver: "0x..",
                 contractAddress: "0x.."}
let result = await Moralis.transfer(options)

Now i have this code, still large

const options = {type: "erc20", 
                 amount: Moralis.Units.Token(value, "18"), 
                 receiver: myadress,
                 contractAddress: contract}
let result = await Moralis.transfer(options)
}

I don’t know now what is the problem, I can test in 1-2 hours

If you change in native instead of erc20 you get same pop up in MetaMask?

I get BNB send window with correct amount

12bnb

Ok, so there isn’t the problem with native. What token are you trying to send there, how many decimals has that token? Not all tokens have 18 decimals

ITAM token. this token based on BEP20 and have 18 decimals

Bscscan info:

18

How does MetaMask know the value of that token?

i don’t know. I just trying to tranfer it like in moralis documentation

Did you add that token to MetaMask?