1

I have two servers, one for eth-node, one for web api and user db.

I want to send request to create account from web server to eth server, but i see it can be created by running command like geth account new localy. https://medium.com/@tzhenghao/getting-started-with-geth-c1a30b8d6458

The purpose of this account is to receive and spend eth, which will be mapped with user-account on user-db server.

Anyway to remotely create account from the eth server then get returned address then store it to the user-web server?

I've read the ethclient, but it shows the way to create wallet only, not account https://goethereumbook.org/accounts/

Or i have to write a service on eth server to exec command geth account new to get result and return it to the user-web server?

  • 1
    you need to use web3js to create accounts – wandos Jun 12 at 14:33
  • @wandos i've searched for web3 go client , but there is no reliable library, only python, js, since go-eth was written in Go, but there's no official go-client to work with it? – TomSawyer Jun 12 at 14:37
0

You can use Web3Js to do so. Based on Web3Js documentation you can use the code below to create an account using a web3js call. Make sure you use the right version web3js the code below is for v1.0+ beta.

Link to documentation:

Documentation link

Sample Code:

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

web3.eth.accounts.create('2435@#@#@±±±±!!!!678543213456764321§34567543213456785432134567');
> {
    address: "0xF2CD2AA0c7926743B1D4310b2BC984a0a453c3d4",
    privateKey: "0xd7325de5c2c1cf0009fac77d3d04a9c004b038883446b065871bc3e831dcd098",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}

web3.eth.accounts.create(web3.utils.randomHex(32));
> {
    address: "0xe78150FaCD36E8EB00291e251424a0515AA1FF05",
    privateKey: "0xcc505ee6067fba3f6fc2050643379e190e087aeffe5d958ab9f2f3ed3800fa4e",
    signTransaction: function(tx){...},
    sign: function(data){...},
    encrypt: function(password){...}
}
  • i though web3.eth.accounts.create can be used for local node only? for remote node we have to use web3.personal.newAccount , i got error: AttributeError: 'list' object has no attribute 'create' if i use web3.eth.accounts.create on web3py – TomSawyer Jun 12 at 18:18

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.