你们知道Coinbase是否允许通过他们的Api以Xapo的方式自动创建用户? 基本上我需要为Web应用程序上的用户生成钱包地址。 如果不可能,任何创新的想法或替代品都欢迎! 感谢
答案 0 :(得分: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