Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I Buy or Sell erc20 token with using web3.js?

Tags:

ico

web3js

erc20

Which function will I use in web3.js for buying erc20 token from my website?

like image 695
md shaiful islam Avatar asked Oct 02 '19 05:10

md shaiful islam


1 Answers

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

like image 53
iAmADeveloper Avatar answered Oct 18 '22 19:10

iAmADeveloper