3

你们知道 Coinbase 是否允许像 Xapo 那样通过他们的 Api 自动创建用户?基本上我需要在 web app 上为用户生成一个钱包地址。如果不可能,欢迎任何创新的想法或替代方案!谢谢

4

1 回答 1

0

这就是我在 Rails 应用程序中所做的。

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
于 2015-07-11T00:28:52.297 回答