Reputation: 123
Which function will I use in web3.js for buying erc20 token from my website?
Upvotes: 5
Views: 3821
Reputation: 667
It depends on your web3 version. if you are using 1.2.1
You first need to create a raw transaction and then sign it with your private key. Once you have signed transaction with you, you can use the sendSignedTransaction
method to send transaction to the blockchain. Refer this
For a raw transaction, you need to send some ether
(depends on token price and token value you want to purchase). The token contract will be using the payable function to receive ether on the smart contract.
Once the smart contract receives the amount the sending address will get the desired amount of tokens.
The other option would be by using MetaMask Extension
Upvotes: 4