Amazon clone tutorial problem on Moralis.transfer not opening metamask

Hi. Completed the tutorial about “Amazon clone with Moralis”. It’s not working. Here is the part where am having an issue:

import { Select, Button, Modal, Input } from 'antd'
import { ShoppingCartOutlined } from '@ant-design/icons'
import { useState } from 'react'
import { useMoralis } from 'react-moralis'

const { Option } = Select

function Purchase({ book }) {
  const [isModalVisible, setIsModalVisible] = useState(false)
  const [delivery, setDelivery] = useState('')
  const { Moralis, account } = useMoralis()

  const handleOk = async () => {
    // Get The Price of MATIC

    const options = {
      address: '0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0',
      chain: 'eth',
    }
    const price = await Moralis.Web3API.token.getTokenPrice(options)

    const priceMatic = book.price / price.usdPrice

    // Send Matic to book store owner address

    const options1 = {
      type: 'native',
      amount: Moralis.Units.ETH(priceMatic),
      receiver: '0xf6aE1d525c27Dd2fd4Fc71ce56a7e10Eb71d2***',
    }

    
    let result = await Moralis.transfer(options1)

when pressing the “ok” button Metamask does not pop up to complete the transfer.

Tried to even copy the code from project’s github, still not working.

Someone advised me to somehow use “await Moralis.enableWeb3()”…still no result.

So, does the tutorial contain a mistake? Or what the hell am I doing wrong?!

The dude kept on saying “how awesome is that, one line of code one line of code…” one line of code seems not to be working))))

what happens when it doesn’t work?
you see any error in the browser console?

See the photo attached for console.

sorry to disturb u again, but I really wish that “how cool is that dude” from tutorial to look back at its code and find the error.

can you print this options object to see what is the value for that amount?

what version or Moralis SDK you have?

man, I am not blockchain programmer with 20y of experience. Am just learning something with “one line of code Moralis”))) I mean, I not only have followed step by step by that “cool guys” tutorial, but am even git cloning that entire project’s code from github, still doesn’t work. Even installed “mumbai testnet” instead of polygon mainnet, still same shit…

no idea what sdk is, but the video is just 23 days old, I guess I am up to date.

here is it’s github code: https://github.com/IAmJaysWay/amazon-clone-full/blob/main/src/components/Purchase.js

console.log(options1) shows this

we will have to debug it, maybe the problem is not with the code that runs and it is with some configuration

what do you have in metamsk added for that network as PRC node (a public RPC node, a speedy node)?
how much testnet native currency do you have in your account in that network for the address that is in metamask?

Have 3.2 Matic. Am using mainnet now.

const options = {
address: ‘0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0’,
chain: ‘eth’,
}

As for the RPC node, pls see attached

what do these values mean for address and chain?

Haha, u asking me? address is Matic token address from etherscan, chain is ‘eth’, probably because both matic and bnb are using EVM hahaha… That’s what that cool guy did in his tutorial and can also find it in the github page of the project I sent to u…

got it, it has a comment above:

/ Get The Price of MATIC
const options = {
address: "0x7D1AfA7B718fb893dB30A3aBc0Cfc608AaCfeBB0",
chain: "eth"
};
const price = await Moralis.Web3API.token.getTokenPrice(options);
const priceMatic = book.price / price.usdPrice;

that is only used to get the price of Matic token

I tried even to get rid of it, and directly put the prices in Matic on the website. still same problem:(

const options1 = {
type: "native", 
amount: Moralis.Units.ETH(priceMatic), 
receiver: "xxxxx"
}
let result = await Moralis.transfer(options1)

this part, you could test it with some smaller fixed amount first, from your image it looks like it tries to transfer 72 native tokens

Ok, will test it now. But in that case, most probably it should have opened the metamask window and said " not enough funds", whereas here it doesn’t respond at all…

holy shit! damn it, it worked!!! dude, u the beeeeest!!! what a silly issue that was! f’ck!

1 Like

I also came across an issues here, it doesn’t allow me to list products above $100, anything above that and it won’t display…what can I do about this???