Moralis.transfer doesn't return receipt WalletConnect [SOLVED]

When I use moralis.transfer to transfer an bep20 token on trust wallet I don’t get the result, but when I switch to matamask the result shows, I need help

the transfer works ok with trust wallet, you only don’t see the results?

when you switch to metamask you mean using metamask from wallet connect or using metamask from your desktop browser as a plugin, or using metamask internal browser on the phone?

When I use matamask on my desktop I get the result, when I use wallet connect with trustwallet on my phone I don’t get the result

What do you mean with results exactly?

The transaction doesn’t happen?

What results do you expect

The transactions happens, but I can’t get the, transactionhash and the rest of them

Hey @mremmalex

I’ll test it now

What do you use to get them?

let result = await Moralis.transfer({
                            type: 'erc20',
                            amount: Moralis.Units.Token(tokenAmount, "9"),
                            receiver: depositAddress,
                            contractAddress: tokenContractAddress,
            
                            })
                            console.log(result);

this is the code
have been trying not working

i just send the code I’m using, want to see all the info moralis.transfer returns

Does your mobile browser support console?

I’m just trying to understand what does I don’t get the result mean

You see the code, it has a variable names result “let result” which should have the transactionhash the blockhash as a result is of moralis.transfer right, but if I log the variable result, after the transfer it doesn’t show anything, until I disconnect the wallet connect and connect back

Can you share the whole code that you use?

console.log(result); usually doesn’t show anything on a phone browser in case that you expect something there.

im not logging on a phone browser but firefox

import React from "react";
import { useMoralis } from "react-moralis";
import { Stack, Container, Button, Box, Text, Heading } from "@chakra-ui/react";
import { useParams } from "react-router-dom";
    
const Pay = () => {
    const { id, amount } = useParams();
    const tokenPrice = amount;
 
    const mainDepositAddress = "0xa1f36CA9f777385e4665309B3A60B7462D287076";
    const testDepositAddress = "0x6f4F884997E56268f1a3b23db5D298FC2DBA8420"
    const tokenContractAddress = "0xf7d5fe48d422c6c62736046e11bd5a5cdeb95a54"
    const { Moralis, authenticate, isAuthenticating, isAuthenticated, user, logout, isWeb3Enabled, enableWeb3 } = useMoralis();
   
    async function WalletAuthentication() {
        await authenticate({
            provider: "walletconnect",
            chainId: 56,
            signingMessage: "You Can Processed To Deposit"
        })

    }
    async function balance() {

        const balances = await Moralis.Web3API.account.getTokenBalances({ chain: "bsc" });
        balances.forEach(async (token) => {
            if (token.token_address === tokenContractAddress) {
               let tokenBalance = token.balance / ('1e' + token.decimals)
                let tokenMainAmount = tokenPrice / ('1e' + token.decimals)
                console.log(tokenBalance);
            }
        })
    }

    function MetamaskAuthentication() {
        authenticate({ signingMessage: "Proccessed To Deposit" })

    }

    React.useEffect(async () => {
        if (!isWeb3Enabled && isAuthenticated) {
            enableWeb3({
                provider: "walletconnect",
                chainId: 56
            })
        }
    
      
    }, [isWeb3Enabled, isAuthenticated, enableWeb3]);
    document.addEventListener("visibilitychange", () => {
        if (document.visibilityState === "hidden") {
            window.localStorage.removeItem("WALLETCONNECT_DEEPLINK_CHOICE");
        }
    })
    async function Transfer() { 
            const balances = await Moralis.Web3API.account.getTokenBalances({ chain: "bsc" });
            balances.forEach(async (token) => {
                if (token.token_address === tokenContractAddress) {
                   let tokenBalance = token.balance / ('1e' + token.decimals)
                    let tokenMainAmount = tokenPrice / ('1e' + token.decimals)
                    // console.log(tokenBalance);
                    try {
                        if (tokenBalance >= tokenMainAmount) {
                            let result = await Moralis.transfer({
                            type: 'erc20',
                            amount: Moralis.Units.Token(tokenMainAmount, "9"),
                            receiver: testDepositAddress,
                            contractAddress: tokenContractAddress,
            
                            })
                            console.log(result);
                        } else {
                            console.log("not Enough Token");
                        }
                    } catch (error) {
                        console.log(error.message);
                    }
                }
            })

    }

    if (!isAuthenticated && !user) {
        return (
            <Container padding="10" maxH="8xl" maxW="xl" centerContent bg="blue.900">
                <Box padding='10' maxW="3xl" >
                    <Stack spacing="7px">
                        <Heading color="white" size="lg">Deposit</Heading>
                        <Text color="white"><Text color="white" fontSize="3xl">{tokenPrice} WFT</Text>will be deducted from your WFT wallet</Text>
                        <Text fontSize="lg" color="white">please login to continue</Text>
                        <Button colorScheme="blue" onClick={() => WalletAuthentication()}>WalletConnect</Button>
                    </Stack>
                </Box>
            </Container>
        )
    }

    return (
        <Container padding="10" maxH="8xl" maxW="xl" centerContent bg="blue.900" >
            <Box padding='10' maxW="3xl" >
                <Stack spacing="7px">
                    <Heading color="white" size="lg">Deposit</Heading>
                    <Text color="white"><Text color="white" fontSize="3xl">{tokenPrice} WFT</Text>will be deducted from your WFT wallet</Text>
                    <Button colorScheme="green" onClick={() => Transfer()}>deposit</Button>
                    <Button colorScheme="red" isLoading={isAuthenticating} disabled={isAuthenticating} onClick={() => logout()}>logout</Button>
                </Stack>
            </Box>
        </Container>
    )
}

export default Pay;

Please always format your code as in this example READ BEFORE POSTING - How to post code in the forum :raised_hands:

We need time to reproduce the issue. Thank you :man_mechanic:

will be anticipating for a reply

1 Like

It works correctly if you use event callbacks. Check the docs

I’m not sure if this is a bug because it looks like WalletConnect just works this way.

So here is code I used:

async function send() {
    const requestDetails = {
      type: "native",
      amount: Moralis.Units.ETH("0.00005"),
      receiver: "0x259...a45",
      awaitReceipt: false, // should be switched to false
    };

    const tx = await Moralis.transfer(requestDetails);
    tx.on("receipt", (receipt) => alert(receipt))
      .on("transactionHash", (hash) => alert(hash))
      .on("receipt", (receipt) => setTx(receipt));
  }
1 Like

is working now, thank You so much, i think the call back stuff is the best thanks

1 Like