get cake balance from bsc wallet

This commit is contained in:
João Geonizeli
2021-09-15 23:45:50 -03:00
parent d01502d765
commit fb957803cc
24 changed files with 453 additions and 79 deletions

View File

@@ -0,0 +1,21 @@
# frozen_string_literal: true
class BscClient
include HTTParty
base_uri "api-eu1.tatum.io/v3"
def initialize
@headers = {
"x-api-key": ENV["TATUM_API_KEY"],
}
end
def token_balance(token, token_decimals, wallet_address)
result = self.class.get(
"https://api-eu1.tatum.io/v3/blockchain/token/balance/BSC/#{token}/#{wallet_address}",
headers: @headers
).parsed_response["balance"]
result.to_f / (10**token_decimals)
end
end