Coinbase API: Create a New Bitcoin Wallet for Users with an Email Address

Do you guys know if Coinbase allows automatic user creation through their Api like Xapo does? Basically I need to create a wallet for users in a web application. Any innovative ideas or alternatives if not possible are welcome !!! Thanks to

+3


source to share


1 answer


This is what I am doing in my Rails application.



def create_account
  wallet = Coinbase::Wallet::Client.new(api_key: ENV["COINBASE_KEY"], api_secret: ENV["COINBASE_SECRET"])
  mAccount = check_account
  if mAccount.nil?
    mAccount = wallet.create_account(name: self.email)
  end
  newaddr = mAccount.create_address
  newaddr = newaddr["address"]
  account = Account.new
  account.address = newaddr
  account.user_id = self.id
  account.balance = mAccount["balance"]["amount"]
  account.account_id = mAccount["id"]
  account.save
end
def check_account
  begin
    wallet = Coinbase::Wallet::Client.new(api_key: ENV["COINBASE_KEY"], api_secret: ENV["COINBASE_SECRET"])
    ac = nil
    a = wallet.accounts
    a.each do |account|
      if account["name"] == self.email
        ac = wallet.account(account["id"])
      end
    end
    ac
  rescue Coinbase::Wallet::NotFoundError
    nil
  end
end

      

0


source







All Articles