0

I am trying the example given here and making it like the below:

const transactionParameters = {
              nonce: '0x00', // ignored by MetaMask
              gasPrice: '0x09184e72a000', // customizable by user during MetaMask confirmation.
              gas: '0x2710', // customizable by user during MetaMask confirmation.
              to: '0x75bd01A1608E68557A59F86856130bB7dbe6102e', // Required except during contract publications.
              from: '0x4D0B0b9c84d831bED12C554557d6776f8B17b99d', // must match user's active address.
              value: '1', // Only required to send ether to the recipient from the initiating external account.
              data:
                'INV-003', // Optional, but used for defining smart contract creation and interaction.
              chainId: '0x3', // Used to prevent transaction reuse across blockchains. Auto-filled by MetaMask.
            };
            console.log(transactionParameters)

            const txHash = await ethereum.request({
              method: 'eth_sendTransaction',
              params: [transactionParameters],
            });
            console.log(txHash);

But it is not doing anything. Even not printing the output of console.log(transactionParameters). If remove await ethereum.request one it prints fine. The code which is being called against a click event is given below:

$('.btn-buy').click(function() {
        let price = $(this).data("price")
        let name = $(this).data("name")
        console.log(name,price)
        const transactionParameters = {
              nonce: '0x00', // ignored by MetaMask
              gasPrice: '0x09184e72a000', // customizable by user during MetaMask confirmation.
              gas: '0x2710', // customizable by user during MetaMask confirmation.
              to: '0x75bd01A1608E68557A59F86856130bB7dbe6102e', // Required except during contract publications.
              from: '0x4D0B0b9c84d831bED12C554557d6776f8B17b99d', // must match user's active address.
              value: '1', // Only required to send ether to the recipient from the initiating external account.
              data:
                'INV-003', // Optional, but used for defining smart contract creation and interaction.
              chainId: '0x3', // Used to prevent transaction reuse across blockchains. Auto-filled by MetaMask.
            };
            console.log(transactionParameters)

            const txHash = await ethereum.request({
              method: 'eth_sendTransaction',
              params: [transactionParameters],
            });
            console.log(txHash);
    });
1
  • Metamask will pause the request and ask the user to verify it and modify the inputs, gas amount gas price and all, if it hangs you may need to check your metamask plugin maybe it doesn't work properly so your code waits forever for metamsk to respond. Jul 25 at 18:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.