0
votes

I have created a smart contract that facilitates a token sale. I want a user to be able to press a button that automatically generates an ERC20 wallet that tokens can be sent to.

I am using the truffle HDWallet Provider and Infura. I don't want the user to have to use MetaMask or anything else. I will sign the transactions on the backend using the private key of the user's generated wallet.

How would I go about implementing this so a new wallet is created for every new user that wants to perform a transaction?

1

1 Answers

0
votes

This is the code that allowed me to create a wallet on a button press. I now need to find a way to store the credentials of these wallets so I can sign transactions and transfer tokens to them.

  var bip39 = require('bip39');
  const EthereumUtil = require('ethereumjs-util');
  const hdkey = require('hdkey');

  const mnemonic = bip39.generateMnemonic(); //generates string
  const seed = bip39.mnemonicToSeed(mnemonic); //creates seed buffer

  const root = hdkey.fromMasterSeed(seed);
  const masterPrivateKey = root.privateKey.toString('hex');

  const addrNode = root.derive("m/44'/60'/0'/0/0");
  const pubKey = EthereumUtil.privateToPublic(addrNode._privateKey);
  const addr = EthereumUtil.publicToAddress(pubKey).toString('hex');
  const address = EthereumUtil.toChecksumAddress(addr);