0

I'm trying to create a new account using this script:

let account = web3.eth.accounts.create();

It will return me something like this:

{
address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
signTransaction: function(tx){...},
sign: function(data){...},
encrypt: function(password){...}

}

So I'm having some questions:

  1. Will I be able to use this account to send and receive token (via Metamask maybe) ?
  2. What is the different between web3.eth.accounts.create() and web3.eth.personal.newAccount(password, [callback]) ?
  3. Does Web3JS provide a way for us to automatically transfer and receive tokens ?

I'm new and really need some helps. Every answer will be highly appreciated. Thank u so much !!!

1 Answer 1

1

1- There are two types of Ethereum accounts:

  • Externally owned accounts (EOA)
  • Contract accounts

EOA accounts have a private key (which MUST be kept secret), Contract accounts on the other hand do not have any private key. The accounts that you make through Metamask or web3.js are of EOA type. As long as you have the private key of your account, you would be able to use it with the Metamask or any other web3 compatible Ethereum wallet.

2-web3.eth.accounts.create gives a source of entropy (optional) and creates a new EOA account, and returns the private key and public address of the created account.
According to this page:

The web3-eth-personal package allows you to interact with the Ethereum node’s accounts.

Apparently, your private key for the created account through web3.eth.personal.newAccount is made or kept somewhere on the node, so I personally NEVER EVER use it.

3- I don't know what you mean by automatically transferring or receiving tokens. For sending an ERC20 token, you typically need to sign and submit a transaction using your private key, which can be done through your web wallet or web3.js. For receiving ERC20 tokens, you need nothing to do.

3
  • Wow, this is insanely detailed. Thank you a lots Mr. Btw, the question number 3 relate to this scenarios: I have 50 difference accounts and wanting to use a for loop together with the web3js to automatically loop through these accounts to send some tokens to my main account. So I assume I need to research the "sign" things of web3js right Mr.Ehsan ? Commented Apr 27, 2022 at 12:24
  • If by "token", you mean ERC20, then yes. ERC20 is a standard for managing fungible tokens on Ethereum and other EVM-compatible blockchains. It has a method named transfer (or the safe version safeTransfer) which is used to transfer tokens around. All you need to do is to create a transaction that calls the transfer method, sign the tx using your account's pk and send it to the network through your web3 provider. Web3.js will perform all of these steps for you easily. Commented Apr 27, 2022 at 13:06
  • Thank u so much, you saved my day Commented Apr 27, 2022 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.