Create a new transaction

yeah, the web3.eth.sendTransaction works for me, therefore the question can be marked as solved.

2 Likes

@vladimirwebatix Can you share with us what you did to make your transaction work?

yeah, sure thing, consider that code snippet:

let moralis_node = {};

Moralis.Web3.authenticate().then(async (current_user) => {
  moralis_node.web3 = await Moralis.Web3.enable();
});

// This object has to be filled somehow with values before the add transaction button is clicked
let transaction_data ={};

add_transaction.button.addEventListener('click', () => {
  const transactionObject = {
    from: Moralis.User.current().get('ethAddress'),
    to: transaction_data.destination_address,
    value: transaction_data.amount,
    gasPrice: transaction_data.gas_price,
    gas: transaction_data.gas_limit
  };
  moralis_node.web3.eth.sendTransaction(transactionObject, (error, result) => {
    console.log("The sendTransaction error == ", error);
    console.log("The sendTransaction result == ", result);
  });
});

Thank you very much. I managed to make a Metamask popup appear with a 0 amount. Now I will dig deeper.
It is a pity this is not documented in the Moralis doc : https://docs.moralis.io/web3

2 Likes

The docs assume the reader has some knowledge of Web3 already. If you have any suggestion on how to improve the docs please let us know.

Once you call Morals.Web3.enable() this gives you a fully functional web3 instance connected to the user’s wallet. At this point the Moralis docs link to the Web3 docs here

https://web3js.readthedocs.io/

Bookmark that page. Most of the functionality you’ll need is in web3.eth and web3.Contract

Thank you for the response.

If you have any suggestion on how to improve the docs please let us know.

Actually I think what can be useful is that the Moralis doc can provide an example in the helper function section with sendTransaction along with getTransactions(), etc.

So in the end, I managed to have a button sending a ETH transaction to Metamask, which is a good start.

Hi @vladimirwebatix, do you know if there is some example code to triggering a transfer from account to another on button click or similar please?

Many thanks in advance for your reply / support!
Leonidas

1 Like

Hi Leonidas.

You can use my code snippet above, just be aware, that add_transaction.button should be equal to your button HTML element, something like that:

let add_transaction = {};
add_transaction.button = document.getElementById('my_transfer_button');

Awesome thank you so much …I was playing around with this last night but got nowhere.
I will give it another shot :slight_smile: thanks man!

Leonidas

1 Like

Hii, I’m trying to create a simple dApp in React-native.
I tried to use react-moralis library in react-native but stuck at the ETH transaction.
I want to send test ETH using Ropsten Text Network to another wallet but not getting conformation from MetaMask

Video : https://vimeo.com/650189932

it asks for login to see that video, do you get to sign the transaction? the authentication with wallet connect works?

Thanks for replying.
yes, the authentication with wallet connect works but does not get a transaction pop-up.
I used https://www.npmjs.com/package/react-moralis#useweb3transfer

maybe you need to use enableWeb3({provider:'walletconnect'})

usage:
const { web3, enableWeb3, isWeb3Enabled, isWeb3EnableLoading, web3EnableError } = useMoralis();

enableWeb3(); or enableWeb3({provider:‘walletconnect’});

getting error like this :
web3EnableError [TypeError: undefined is not an object (evaluating ‘connector.connect’)]

but somehow I think that it has to use web3 for authentication to work

Authentication is successed using

const { authenticate} = useMoralis();
authenticate({ connector })

what is in connector variable?
does it work if you use enableWeb3({connector}) ?

connnector contains walletconnect
enableWeb3({connector}) is not working

maybe you can ask you question in this thread specific to react native boilerplate: Ethereum React Native Boilerplate Questions

Okay @cryptokid thank you