Files
assets/internal/info/external/trc20.go
T
2204745e34 Add Injective assets (#27191)
* Create logo .png

* Create logo.png

* Create info.json

* Create logo.png

* Create info.json

* Create info.json

* Create logo.png

* Create info.json

* Create logo.png

* Create info.json

* Update info.json

* Update info.json

* Update info.json

* Update info.json

* Update info.json

* Create logo.png

* Delete logo .png

* tokens

* tokens

* tokens

* tokens

* tokens

* tokens

---------

Co-authored-by: Denis <136321897+defisaur@users.noreply.github.com>
2024-01-12 15:49:54 +04:00

39 lines
838 B
Go

package external
import (
"errors"
"fmt"
"github.com/trustwallet/assets-go-libs/http"
)
const trc20APIURL = "https://apilist.tronscan.io/api/token_trc20?contract=%s"
type TRC20TokensResponse struct {
TRC20Tokens []struct {
Symbol string `json:"symbol"`
Decimals int `json:"decimals"`
HoldersCount int `json:"holders_count"`
} `json:"trc20_tokens"`
}
func GetTokenInfoForTRC20(tokenID string) (*TokenInfo, error) {
url := fmt.Sprintf(trc20APIURL, tokenID)
var res TRC20TokensResponse
err := http.GetHTTPResponse(url, &res)
if err != nil {
return nil, err
}
if len(res.TRC20Tokens) == 0 {
return nil, errors.New("not found")
}
return &TokenInfo{
Symbol: res.TRC20Tokens[0].Symbol,
Decimals: res.TRC20Tokens[0].Decimals,
HoldersCount: res.TRC20Tokens[0].HoldersCount,
}, nil
}