0

I am new to the crypto world, so trying to get my hands dirty with some code. I am attempting to create an account and do some operations using the same account. But get accounts doesn't return the account I created.

Code

if __name__ == '__main__':
    print_hi('PyCharm')
    w3 = Web3(Web3.HTTPProvider('https://mainnet.infura.io/v3/<appKey>'))
    print(w3.isConnected())
    account = w3.eth.account.create()
    print(account)
    accounts = w3.eth.get_accounts()
    print(accounts)

In the account prints empty array. Also does this create an account in mainnet of infura ? Is there place/dashboard where I can check if the account was created ?

1

account = w3.eth.account.create()

I can't immediately see that this method exists in Web3.py (I can't see it in the docs). In Web3.js it returns the following:

web3.eth.accounts.create();
> {
    address: "0xb8CE9ab6943e0eCED004cDe8e3bBed6568B2Fa01",
    privateKey: "0x348ce564d427a3311b6536bbcff9390d69395b06ed6c486954e971d960fe8709",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}

accounts = w3.eth.get_accounts()

Again, for Web3.py, I think this should be accounts = w3.eth.accounts() (see here in the docs).

Also does this create an account in mainnet of infura ?

It doesn't create you an account in a particular place. It generates you a private key, corresponding public key, and derives you an address. The private key is valid on both the mainnet and testnets. The private key sits on your local machine (or resides in your wallet, if you're using one) and allows you to sign transactions sent whichever network you're connected to. Infura is a third-party provider that gives you access to an RPC (or websocket) endpoint so you can interact with the network.

Is there place/dashboard where I can check if the account was created ?

So all accounts (technically) already exist. Whether or not someone has generated the private key that equates to each account is another matter.

You can't know whether or not someone has generated a private key to a particular address, unless that address has sent a transaction, which in turn leaves a record in the blockchain data. That way you know another human (or bot), somewhere, has the private key for that address.

So when you run the create() method in your code, it generates you a private key. No one can know that you generated that key until you send your first transaction. At that point the private key/address is known to exist.

A private key is just a string of 64 hexadecimal characters. You can generate it any way you like, for example, by randomly picking the characters out of a hat, or using dice. (This would make it more difficult to them create the corresponding public key and address, which is why people generally use wallets. But you get the idea.)

2
  • Understood the account creation part, but why does get_account return an empty arrray. Shouldnt it have the account that got create. FYI, I can see that response after account creation. – vishnu satis May 31 at 6:04
  • Hmm, did you try just running w3.eth.accounts()? Does that also return an empty array? – Richard Horrocks May 31 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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