React-moralis, trying to connect contract on bsc_testnet, sending BUSD

Hi, I’m trying to send busd on bsc-testnet by executefunction on Moralis.executeFunction
using template from eth-boilerplate

Contract address’s link here: https://testnet.bscscan.com/address/0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee#code

import { useMoralis } from "react-moralis";
import { useState } from "react";
import { notification } from "antd";

const abi = [
    {
        "anonymous": false, "inputs": [{ "name": "_to", "type": "address" }, { "name": "_value", "type": "uint256" }], "name": "transfer",
        "type": "event"
    }
]


export default function BUSDTest() {
    const { Moralis } = useMoralis();
    const [responses, setResponses] = useState({});
    const options = {
        abi: abi,
        contractAddress: "0xeD24FC36d5Ee211Ea25A80239Fb8C4Cfd80f12Ee",
        functionName: "transfer",
        params: {
            _to: "0x44dCF968b595768C7f8C5486899790C44d809F50",
            _value: 1
        },
    }
    const openNotification = ({ message, description }) => {
        notification.open({
            placement: "bottomRight",
            message,
            description,
        });
    };

    return (<div>
        <button onClick={async () => {
            const tx = await Moralis.executeFunction({ awaitReceipt: false, ...options });
            tx.on("receipt", (receipt) => {
                setResponses({ ...responses, "name": { result: null, isLoading: false } });
                openNotification({
                    message: "📃 New Receipt",
                    description: `${receipt.transactionHash}`,
                });
                console.log("🔊 New Receipt: ", receipt);
            })
        }}>Send 1 BUSD</button>
    </div>)
}

I got an error
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading ‘apply’)
after click the button
image

what is it? I don’t know how to fix this.

looks like the ABI type is event, which should not be used in Moralis.executeFunction, try this ABI instead:

{"constant":false,"inputs":[{"name":"_to","type":"address"},{"name":"_value","type":"uint256"}],"name":"transfer","outputs":[{"name":"","type":"bool"}],"payable":false,"stateMutability":"nonpayable","type":"function"},

the type should be function. Also if you are transferring ERC20, we have Moralis.transfer to help you do that easily https://docs.moralis.io/moralis-server/sending-assets#transferring-erc20-tokens :raised_hands:

1 Like

it’s work, thanks a lot.

1 Like