Thank you for your answer, but I still wish to know how to make transactions on blockchain using Moralis platform.
For making on-chain transactions see Web3 docs here
https://docs.moralis.io/web3
To get notifications of transactions and contract events see here:
https://docs.moralis.io/real-time-transactions
Thanks, I’ve seen these topics already. I think, you directed me to this piece of code on https://docs.moralis.io/web3
const web3 = await Moralis.Web3.enable(); const contract = new web3.eth.Contract(contractAbi, contractAddress);
It’s not actually what I want to invoke, but later I will try to call a smart contract method too (the way shown in the Moralis Web3 docs).
Well, I hope that after the crypto login with Metamask the logined EthAddress becomes unlocked, so I will be able to use the web3.eth.signTransaction => web3.eth.sendSignedTransaction. Will give that a try.
yes. after calling Moralis.Web3.enable()
in the browser it will prompt the user to sign in with their wallet. The web3
instance you get back from calling this method will then be connected to the user’s wallet and be able to sign transactions.
yeah, the web3.eth.sendTransaction works for me, therefore the question can be marked as solved.
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
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
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 thanks man!
Leonidas
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 })