smart-contracts | Main smart contracts for Kyber Network | Cryptocurrency library
kandi X-RAY | smart-contracts Summary
Support
Quality
Security
License
Reuse
Currently covering the most popular Java, JavaScript and Python libraries. See a Sample Here
smart-contracts Key Features
smart-contracts Examples and Code Snippets
Trending Discussions on smart-contracts
Trending Discussions on smart-contracts
QUESTION
What I am trying to do is to parse nested json data into a Java object using Gson and print it out with customized toString().
The Json Content
{"data": [
{
"symbol": "BTC",
"circulating_supply": 18975050,
"last_updated": "2022-03-05T13:54:00.000Z",
"total_supply": 18975050,
"cmc_rank": 1,
"self_reported_circulating_supply": null,
"platform": null,
"tags": [
"mineable",
"pow",
"sha-256",
"store-of-value",
"state-channel",
"coinbase-ventures-portfolio",
"three-arrows-capital-portfolio",
"polychain-capital-portfolio",
"binance-labs-portfolio",
"blockchain-capital-portfolio",
"boostvc-portfolio",
"cms-holdings-portfolio",
"dcg-portfolio",
"dragonfly-capital-portfolio",
"electric-capital-portfolio",
"fabric-ventures-portfolio",
"framework-ventures-portfolio",
"galaxy-digital-portfolio",
"huobi-capital-portfolio",
"alameda-research-portfolio",
"a16z-portfolio",
"1confirmation-portfolio",
"winklevoss-capital-portfolio",
"usv-portfolio",
"placeholder-ventures-portfolio",
"pantera-capital-portfolio",
"multicoin-capital-portfolio",
"paradigm-portfolio"
],
"date_added": "2013-04-28T00:00:00.000Z",
"quote": {"USD": {
"fully_diluted_market_cap": 820131199762.62,
"last_updated": "2022-03-05T13:54:00.000Z",
"market_cap_dominance": 42.252,
"percent_change_30d": 6.81621153,
"percent_change_1h": -0.42008562,
"percent_change_24h": -5.71623656,
"market_cap": 741049072478.8419,
"volume_change_24h": -11.0241,
"price": 39053.8666553628,
"percent_change_60d": -16.6843952,
"volume_24h": 26123993408.855915,
"percent_change_90d": -21.03603335,
"percent_change_7d": -0.10097865
}},
"num_market_pairs": 9214,
"name": "Bitcoin",
"max_supply": 21000000,
"id": 1,
"self_reported_market_cap": null,
"slug": "bitcoin"
},
{
"symbol": "ETH",
"circulating_supply": 119834013.5615,
"last_updated": "2022-03-05T13:54:00.000Z",
"total_supply": 119834013.5615,
"cmc_rank": 2,
"self_reported_circulating_supply": null,
"platform": null,
"tags": [
"mineable",
"pow",
"smart-contracts",
"ethereum-ecosystem",
"coinbase-ventures-portfolio",
"three-arrows-capital-portfolio",
"polychain-capital-portfolio",
"binance-labs-portfolio",
"blockchain-capital-portfolio",
"boostvc-portfolio",
"cms-holdings-portfolio",
"dcg-portfolio",
"dragonfly-capital-portfolio",
"electric-capital-portfolio",
"fabric-ventures-portfolio",
"framework-ventures-portfolio",
"hashkey-capital-portfolio",
"kenetic-capital-portfolio",
"huobi-capital-portfolio",
"alameda-research-portfolio",
"a16z-portfolio",
"1confirmation-portfolio",
"winklevoss-capital-portfolio",
"usv-portfolio",
"placeholder-ventures-portfolio",
"pantera-capital-portfolio",
"multicoin-capital-portfolio",
"paradigm-portfolio",
"injective-ecosystem",
"bnb-chain"
],
"date_added": "2015-08-07T00:00:00.000Z",
"quote": {"USD": {
"fully_diluted_market_cap": 316405371023.81,
"last_updated": "2022-03-05T13:54:00.000Z",
"market_cap_dominance": 18.0363,
"percent_change_30d": 1.39750424,
"percent_change_1h": -0.82066438,
"percent_change_24h": -3.20839994,
"market_cap": 316405371023.81366,
"volume_change_24h": -14.3764,
"price": 2640.363629825611,
"percent_change_60d": -31.31982292,
"volume_24h": 12406258074.91051,
"percent_change_90d": -37.45316954,
"percent_change_7d": -4.71064229
}},
"num_market_pairs": 5543,
"name": "Ethereum",
"max_supply": null,
"id": 1027,
"self_reported_market_cap": null,
"slug": "ethereum"
},
and so on...
]}
POJO Classes : Example
package controller;
import java.util.List;
import javax.annotation.processing.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("jsonschema2pojo")
public class Example {
@SerializedName("data")
@Expose
private List data = null;
public List getData() {
return data;
}
public void setData(List data) {
this.data = data;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(Example.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
sb.append("data");
sb.append('=');
sb.append(((this.data == null)?"":this.data));
sb.append(',');
if (sb.charAt((sb.length()- 1)) == ',') {
sb.setCharAt((sb.length()- 1), ']');
} else {
sb.append(']');
}
return sb.toString();
}
}
POJO Classes : JsonFormatter
package controller;
import java.util.List;
import javax.annotation.processing.Generated;
import com.google.gson.annotations.Expose;
import com.google.gson.annotations.SerializedName;
@Generated("jsonschema2pojo")
public class JsonFormatter {
@SerializedName("symbol")
@Expose
private String symbol;
@SerializedName("circulating_supply")
@Expose
private Float circulatingSupply;
@SerializedName("last_updated")
@Expose
private String lastUpdated;
@SerializedName("total_supply")
@Expose
private Float totalSupply;
@SerializedName("cmc_rank")
@Expose
private Float cmcRank;
@SerializedName("self_reported_circulating_supply")
@Expose
private Object selfReportedCirculatingSupply;
@SerializedName("platform")
@Expose
private Platform platform;
@SerializedName("tags")
@Expose
private List tags = null;
@SerializedName("date_added")
@Expose
private String dateAdded;
@SerializedName("quote")
@Expose
private Quote quote;
@SerializedName("num_market_pairs")
@Expose
private Float numMarketPairs;
@SerializedName("name")
@Expose
private String name;
@SerializedName("max_supply")
@Expose
private Float maxSupply;
@SerializedName("id")
@Expose
private Integer id;
@SerializedName("self_reported_market_cap")
@Expose
private Object selfReportedMarketCap;
@SerializedName("slug")
@Expose
private String slug;
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public Float getCirculatingSupply() {
return circulatingSupply;
}
public void setCirculatingSupply(Float circulatingSupply) {
this.circulatingSupply = circulatingSupply;
}
public String getLastUpdated() {
return lastUpdated;
}
public void setLastUpdated(String lastUpdated) {
this.lastUpdated = lastUpdated;
}
public Float getTotalSupply() {
return totalSupply;
}
public void setTotalSupply(Float totalSupply) {
this.totalSupply = totalSupply;
}
public Float getCmcRank() {
return cmcRank;
}
public void setCmcRank(Float cmcRank) {
this.cmcRank = cmcRank;
}
public Object getSelfReportedCirculatingSupply() {
return selfReportedCirculatingSupply;
}
public void setSelfReportedCirculatingSupply(Object selfReportedCirculatingSupply) {
this.selfReportedCirculatingSupply = selfReportedCirculatingSupply;
}
public Platform getPlatform() {
return platform;
}
public void setPlatform(Platform platform) {
this.platform = platform;
}
public List getTags() {
return tags;
}
public void setTags(List tags) {
this.tags = tags;
}
public String getDateAdded() {
return dateAdded;
}
public void setDateAdded(String dateAdded) {
this.dateAdded = dateAdded;
}
public Quote getQuote() {
return quote;
}
public void setQuote(Quote quote) {
this.quote = quote;
}
public Float getNumMarketPairs() {
return numMarketPairs;
}
public void setNumMarketPairs(Float numMarketPairs) {
this.numMarketPairs = numMarketPairs;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Float getMaxSupply() {
return maxSupply;
}
public void setMaxSupply(Float maxSupply) {
this.maxSupply = maxSupply;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public Object getSelfReportedMarketCap() {
return selfReportedMarketCap;
}
public void setSelfReportedMarketCap(Object selfReportedMarketCap) {
this.selfReportedMarketCap = selfReportedMarketCap;
}
public String getSlug() {
return slug;
}
public void setSlug(String slug) {
this.slug = slug;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(JsonFormatter.class.getName()).append('@').append(Integer.toHexString(System.identityHashCode(this))).append('[');
sb.append("symbol");
sb.append('=');
sb.append(((this.symbol == null)?"":this.symbol));
sb.append(',');
sb.append("circulatingSupply");
sb.append('=');
sb.append(((this.circulatingSupply == null)?"":this.circulatingSupply));
sb.append(',');
sb.append("lastUpdated");
sb.append('=');
sb.append(((this.lastUpdated == null)?"":this.lastUpdated));
sb.append(',');
sb.append("totalSupply");
sb.append('=');
sb.append(((this.totalSupply == null)?"":this.totalSupply));
sb.append(',');
sb.append("cmcRank");
sb.append('=');
sb.append(((this.cmcRank == null)?"":this.cmcRank));
sb.append(',');
sb.append("selfReportedCirculatingSupply");
sb.append('=');
sb.append(((this.selfReportedCirculatingSupply == null)?"":this.selfReportedCirculatingSupply));
sb.append(',');
sb.append("platform");
sb.append('=');
sb.append(((this.platform == null)?"":this.platform));
sb.append(',');
sb.append("tags");
sb.append('=');
sb.append(((this.tags == null)?"":this.tags));
sb.append(',');
sb.append("dateAdded");
sb.append('=');
sb.append(((this.dateAdded == null)?"":this.dateAdded));
sb.append(',');
sb.append("quote");
sb.append('=');
sb.append(((this.quote == null)?"":this.quote));
sb.append(',');
sb.append("numMarketPairs");
sb.append('=');
sb.append(((this.numMarketPairs == null)?"":this.numMarketPairs));
sb.append(',');
sb.append("name");
sb.append('=');
sb.append(((this.name == null)?"":this.name));
sb.append(',');
sb.append("maxSupply");
sb.append('=');
sb.append(((this.maxSupply == null)?"":this.maxSupply));
sb.append(',');
sb.append("id");
sb.append('=');
sb.append(((this.id == null)?"":this.id));
sb.append(',');
sb.append("selfReportedMarketCap");
sb.append('=');
sb.append(((this.selfReportedMarketCap == null)?"":this.selfReportedMarketCap));
sb.append(',');
sb.append("slug");
sb.append('=');
sb.append(((this.slug == null)?"":this.slug));
sb.append(',');
if (sb.charAt((sb.length()- 1)) == ',') {
sb.setCharAt((sb.length()- 1), ']');
} else {
sb.append(']');
}
return sb.toString();
}
}
There are also other classes for my POJO, and the way I tried to parse it into Gson is :
Gson gson = new Gson();
Type type = new TypeToken>>() {}.getType();
Map> nodeProperties = gson.fromJson(json.toString(), type);
but when I try to print out its sub values like
for (Map.Entry> set : nodeProperties.entrySet()) {
System.out.println(set.getValue().get(0).getData().get(0).toString());
}
I get the error :
class controller.JsonFormatter cannot be cast to class controller.Example (controller.JsonFormatter and controller.Example are in unnamed module of loader 'app')
What I want to achieve is to print the above json content as like this:
Symbol: BTC
Circulating_supply: 18975050
...
Tags:
mineable
Can anyone please help me out to solve this problem? Thanks in advance!
ANSWER
Answered 2022-Mar-05 at 16:26The issue is in these lines:
Type type = new TypeToken>>() {}.getType();
Map> nodeProperties = gson.fromJson(json.toString(), type);
The TypeToken
is for MapJsonFormatter>>
, but you store the parsed JSON in a variable of type MapExample>>
. Unfortunately Gson.fromJson(..., Type)
does not provide any type safety guarantees, therefore you must make sure that the provided Type
matches the type of the variable you store the result in. Additionally due to Java's type erasure at runtime, you do not notice this JsonFormatter
vs. Example
mismatch until you iterate over the elements, causing the ClassCastException
.
Based on the JSON data you provided, it looks to me like you could just use gson.fromJson(json.toString(), Example.class)
, but please verify whether that is actually correct for your use case.
QUESTION
What I am trying to do is to change a certain JSON file into a custom format, and I have been searching for the information for two days but I haven't figured it out and I have no one to ask about this....
Before Formatting
{
"book": [
{
"id": "01",
"language": "Java",
"edition": "third",
"author": "Herbert Schildt"
},
{
"id": "07",
"language": "C++",
"edition": "second",
"author": "E.Balagurusamy"
}
]
}
Trying to format it into:
Book
Id : 01
Language : Java
...
Id : 07
Language : C++
The actual JSON data is like this:
[
{
"symbol": "BTC",
"circulating_supply": 18729837,
"last_updated": "2021-06-08T10:17:02.000Z",
"total_supply": 18729837,
"cmc_rank": 1,
"platform": null,
"tags": [
"mineable",
"pow",
"sha-256",
"store-of-value",
"state-channels",
"coinbase-ventures-portfolio",
"three-arrows-capital-portfolio",
"polychain-capital-portfolio",
"binance-labs-portfolio",
"arrington-xrp-capital",
"blockchain-capital-portfolio",
"boostvc-portfolio",
"cms-holdings-portfolio",
"dcg-portfolio",
"dragonfly-capital-portfolio",
"electric-capital-portfolio",
"fabric-ventures-portfolio",
"framework-ventures",
"galaxy-digital-portfolio",
"huobi-capital",
"alameda-research-portfolio",
"a16z-portfolio",
"1confirmation-portfolio",
"winklevoss-capital",
"usv-portfolio",
"placeholder-ventures-portfolio",
"pantera-capital-portfolio",
"multicoin-capital-portfolio",
"paradigm-xzy-screener"
],
"date_added": "2013-04-28T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -42.63012856,
"percent_change_1h": 0.38317977,
"last_updated": "2021-06-08T10:17:02.000Z",
"percent_change_24h": -9.36685756,
"market_cap": 619325019564.578,
"price": 33066.22580669431,
"percent_change_60d": -43.54639481,
"volume_24h": 43132365330.36409,
"percent_change_90d": -39.86303315,
"percent_change_7d": -9.21607228
}},
"num_market_pairs": 9722,
"name": "Bitcoin",
"max_supply": 21000000,
"id": 1,
"slug": "bitcoin"
},
{
"symbol": "ETH",
"circulating_supply": 116205430.624,
"last_updated": "2021-06-08T10:17:02.000Z",
"total_supply": 116205430.624,
"cmc_rank": 2,
"platform": null,
"tags": [
"mineable",
"pow",
"smart-contracts",
"ethereum",
"coinbase-ventures-portfolio",
"three-arrows-capital-portfolio",
"polychain-capital-portfolio",
"binance-labs-portfolio",
"arrington-xrp-capital",
"blockchain-capital-portfolio",
"boostvc-portfolio",
"cms-holdings-portfolio",
"dcg-portfolio",
"dragonfly-capital-portfolio",
"electric-capital-portfolio",
"fabric-ventures-portfolio",
"framework-ventures",
"hashkey-capital-portfolio",
"kinetic-capital",
"huobi-capital",
"alameda-research-portfolio",
"a16z-portfolio",
"1confirmation-portfolio",
"winklevoss-capital",
"usv-portfolio",
"placeholder-ventures-portfolio",
"pantera-capital-portfolio",
"multicoin-capital-portfolio",
"paradigm-xzy-screener"
],
"date_added": "2015-08-07T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -34.93326351,
"percent_change_1h": 0.0977492,
"last_updated": "2021-06-08T10:17:02.000Z",
"percent_change_24h": -10.67415695,
"market_cap": 292465567141.6079,
"price": 2516.797756964766,
"percent_change_60d": 20.00514111,
"volume_24h": 38463882117.94565,
"percent_change_90d": 37.73403958,
"percent_change_7d": -3.05561192
}},
"num_market_pairs": 6053,
"name": "Ethereum",
"max_supply": null,
"id": 1027,
"slug": "ethereum"
},
{
"symbol": "USDT",
"circulating_supply": 62280355385.45168,
"last_updated": "2021-06-08T10:16:08.000Z",
"total_supply": 64471767616.826355,
"cmc_rank": 3,
"platform": {
"symbol": "ETH",
"name": "Ethereum",
"token_address": "0xdac17f958d2ee523a2206206994597c13d831ec7",
"id": 1027,
"slug": "ethereum"
},
"tags": [
"store-of-value",
"payments",
"stablecoin",
"stablecoin-asset-backed",
"solana-ecosystem"
],
"date_added": "2015-02-25T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": 0.08689942,
"percent_change_1h": -0.01514305,
"last_updated": "2021-06-08T10:16:08.000Z",
"percent_change_24h": 0.00252658,
"market_cap": 62333503909.90704,
"price": 1.00085337542033,
"percent_change_60d": 0.00890571,
"volume_24h": 88090197454.22122,
"percent_change_90d": 0.02421796,
"percent_change_7d": 0.03190558
}},
"num_market_pairs": 13483,
"name": "Tether",
"max_supply": null,
"id": 825,
"slug": "tether"
},
{
"symbol": "BNB",
"circulating_supply": 153432897,
"last_updated": "2021-06-08T10:17:08.000Z",
"total_supply": 169432897,
"cmc_rank": 4,
"platform": null,
"tags": [
"marketplace",
"centralized-exchange",
"payments",
"binance-smart-chain",
"alameda-research-portfolio",
"multicoin-capital-portfolio"
],
"date_added": "2017-07-25T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -46.98637267,
"percent_change_1h": -0.06201527,
"last_updated": "2021-06-08T10:17:08.000Z",
"percent_change_24h": -12.9766759,
"market_cap": 54032968135.19999,
"price": 352.1602550149333,
"percent_change_60d": -18.72766515,
"volume_24h": 3975040241.706507,
"percent_change_90d": 24.3131346,
"percent_change_7d": 0.46465171
}},
"num_market_pairs": 619,
"name": "Binance Coin",
"max_supply": 170532785,
"id": 1839,
"slug": "binance-coin"
},
{
"symbol": "ADA",
"circulating_supply": 31930548128.29,
"last_updated": "2021-06-08T10:16:09.000Z",
"total_supply": 32681678108.601,
"cmc_rank": 5,
"platform": null,
"tags": [
"mineable",
"dpos",
"pos",
"platform",
"research",
"smart-contracts",
"staking",
"binance-chain"
],
"date_added": "2017-10-01T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -9.47981292,
"percent_change_1h": -1.0109768,
"last_updated": "2021-06-08T10:16:09.000Z",
"percent_change_24h": -10.68780802,
"market_cap": 49082262157.72255,
"price": 1.53715689315826,
"percent_change_60d": 26.8779134,
"volume_24h": 3602351530.9447293,
"percent_change_90d": 31.00161031,
"percent_change_7d": -9.66192067
}},
"num_market_pairs": 276,
"name": "Cardano",
"max_supply": 45000000000,
"id": 2010,
"slug": "cardano"
},
{
"symbol": "DOGE",
"circulating_supply": 129939361256.40326,
"last_updated": "2021-06-08T10:17:03.000Z",
"total_supply": 129939361256.40326,
"cmc_rank": 6,
"platform": null,
"tags": [
"mineable",
"pow",
"scrypt",
"medium-of-exchange",
"memes",
"payments"
],
"date_added": "2013-12-15T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -27.85005369,
"percent_change_1h": -0.39664229,
"last_updated": "2021-06-08T10:17:03.000Z",
"percent_change_24h": -12.06689716,
"market_cap": 42746878864.849754,
"price": 0.32897559639761,
"percent_change_60d": 425.01053128,
"volume_24h": 4256466078.3377676,
"percent_change_90d": 479.75690549,
"percent_change_7d": 1.48509162
}},
"num_market_pairs": 376,
"name": "Dogecoin",
"max_supply": null,
"id": 74,
"slug": "dogecoin"
},
{
"symbol": "XRP",
"circulating_supply": 46151013329,
"last_updated": "2021-06-08T10:17:03.000Z",
"total_supply": 99990399027,
"cmc_rank": 7,
"platform": null,
"tags": [
"medium-of-exchange",
"enterprise-solutions",
"binance-chain",
"arrington-xrp-capital",
"galaxy-digital-portfolio",
"a16z-portfolio",
"pantera-capital-portfolio"
],
"date_added": "2013-08-04T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -42.92640139,
"percent_change_1h": -0.60106842,
"last_updated": "2021-06-08T10:17:03.000Z",
"percent_change_24h": -10.12249253,
"market_cap": 39897934998.12378,
"price": 0.8645083199734,
"percent_change_60d": -15.63161843,
"volume_24h": 4179902561.947919,
"percent_change_90d": 84.29141004,
"percent_change_7d": -14.85218801
}},
"num_market_pairs": 682,
"name": "XRP",
"max_supply": 100000000000,
"id": 52,
"slug": "xrp"
},
{
"symbol": "USDC",
"circulating_supply": 23075185630.71199,
"last_updated": "2021-06-08T10:17:04.000Z",
"total_supply": 23075185630.71199,
"cmc_rank": 8,
"platform": {
"symbol": "ETH",
"name": "Ethereum",
"token_address": "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
"id": 1027,
"slug": "ethereum"
},
"tags": [
"medium-of-exchange",
"stablecoin",
"stablecoin-asset-backed"
],
"date_added": "2018-10-08T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": 0.05408204,
"percent_change_1h": -0.00816775,
"last_updated": "2021-06-08T10:17:04.000Z",
"percent_change_24h": 0.00649147,
"market_cap": 23084217521.810787,
"price": 1.00039141141672,
"percent_change_60d": -0.05832072,
"volume_24h": 2455031484.812885,
"percent_change_90d": 0.02446002,
"percent_change_7d": -0.0056865
}},
"num_market_pairs": 1068,
"name": "USD Coin",
"max_supply": null,
"id": 3408,
"slug": "usd-coin"
},
{
"symbol": "DOT",
"circulating_supply": 945735752.6497443,
"last_updated": "2021-06-08T10:17:05.000Z",
"total_supply": 1081259867.5039322,
"cmc_rank": 9,
"platform": null,
"tags": [
"substrate",
"polkadot",
"binance-chain",
"polkadot-ecosystem",
"three-arrows-capital-portfolio",
"polychain-capital-portfolio",
"blockchain-capital-portfolio",
"boostvc-portfolio",
"cms-holdings-portfolio",
"coinfund-portfolio",
"fabric-ventures-portfolio",
"fenbushi-capital-portfolio",
"hashkey-capital-portfolio",
"kinetic-capital",
"1confirmation-portfolio",
"placeholder-ventures-portfolio",
"pantera-capital-portfolio",
"exnetwork-capital-portfolio"
],
"date_added": "2020-08-19T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -45.72649058,
"percent_change_1h": -0.3486271,
"last_updated": "2021-06-08T10:17:05.000Z",
"percent_change_24h": -15.05195784,
"market_cap": 20076748179.497543,
"price": 21.22870804370766,
"percent_change_60d": -48.77804479,
"volume_24h": 2421158822.0532265,
"percent_change_90d": -44.73258504,
"percent_change_7d": -5.5027651
}},
"num_market_pairs": 202,
"name": "Polkadot",
"max_supply": null,
"id": 6636,
"slug": "polkadot-new"
},
{
"symbol": "UNI",
"circulating_supply": 575107764.052485,
"last_updated": "2021-06-08T10:16:11.000Z",
"total_supply": 1000000000,
"cmc_rank": 10,
"platform": {
"symbol": "ETH",
"name": "Ethereum",
"token_address": "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984",
"id": 1027,
"slug": "ethereum"
},
"tags": [
"decentralized-exchange",
"defi",
"dao",
"yield-farming",
"amm",
"coinbase-ventures-portfolio",
"three-arrows-capital-portfolio",
"governance",
"blockchain-capital-portfolio",
"defiance-capital",
"alameda-research-portfolio",
"a16z-portfolio",
"pantera-capital-portfolio",
"parafi-capital",
"paradigm-xzy-screener"
],
"date_added": "2020-09-17T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": -40.90238231,
"percent_change_1h": -0.57439386,
"last_updated": "2021-06-08T10:16:11.000Z",
"percent_change_24h": -11.84522167,
"market_cap": 13448377375.304375,
"price": 23.38409984337659,
"percent_change_60d": -23.21587997,
"volume_24h": 569769688.2472888,
"percent_change_90d": -26.98611642,
"percent_change_7d": -13.63660968
}},
"num_market_pairs": 270,
"name": "Uniswap",
"max_supply": 1000000000,
"id": 7083,
"slug": "uniswap"
},
{
"symbol": "ICP",
"circulating_supply": 124103517.19,
"last_updated": "2021-06-08T10:17:07.000Z",
"total_supply": 469293126.8967923,
"cmc_rank": 11,
"platform": null,
"tags": [
"platform",
"distributed-computing",
"polychain-capital-portfolio",
"exnetwork-capital-portfolio"
],
"date_added": "2021-03-23T00:00:00.000Z",
"quote": {"USD": {
"percent_change_30d": 0,
"percent_change_1h": -0.08952838,
"last_updated": "2021-06-08T10:17:07.000Z",
"percent_change_24h": -15.3124386,
"market_cap": 10992912823.823347,
"price": 88.57857595601757,
"percent_change_60d": 0,
"volume_24h": 260287850.43941185,
"percent_change_90d": 0,
"percent_change_7d": -20.06340267
}},
"num_market_pairs": 33,
"name": "Internet Computer",
"max_supply": null,
"id": 8916,
"slug": "internet-computer"
},
... and so on
]
What I have been trying so far is to convert the JSONObject into a HashMap:
HashMap rs = new ObjectMapper().readValue(json.toString(), HashMap.class);
But I do not really know what to do now...
Someone told me to use Jackson or GSon or nested HashMap, but I don't know how it would solve the problem...
Can anyone please help me? Thanks in advance..!
ANSWER
Answered 2022-Mar-02 at 18:45Don’t use a HashMap. Create real data classes:
public class Library {
private Book[] book = { };
public Book[] getBook() {
return book;
}
public void setBook(Book[] books) {
this.book = books;
}
}
public class Book {
private String id;
private String language;
private String edition;
private String author;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getLanguage() {
return language;
}
public void setLanguage(String language) {
this.language = language;
}
public String getEdition() {
return edition;
}
public void setEdition(String edition) {
this.edition = edition;
}
public String getAuthor() {
return author;
}
public void setAuthor(String author) {
this.author = author;
}
}
Now you can pass Library.class
instead of HashMap.class.
QUESTION
I am reading through UniswapV2 docs and can't understand the inputs of addLiquidity
method properly. As listed in the docs:
amountAMin
(uint): Bounds the extent to which the B/A price can go up before the transaction reverts. Must be <= amountADesired.
amountBMin
(uint): Bounds the extent to which the A/B price can go up before the transaction reverts. Must be <= amountBDesired.
What does it mean? Can you please give an example? Let's say, I set amountADesired
and amountBDesired
to 4 and amountAMin
and amountBMin
to 1. What will happen?
ANSWER
Answered 2022-Feb-10 at 14:01blockchain transactions are not immediate, but must queue before being mined on the blockchain and be effective
When you add liquidity given amountADesired
you have to give it amountBDesired
in proportion to the existing pair (example pair: 2:1 you have to put 2 tokens A and 1 token B)
once you send the transaction, before it is mined it may happen that others make operations on that liquidity pool, changing the proportion accordingly
by entering amountAmin
and amountBmin
you are practically telling him: "as long as the proportion is between amountADesired
:amountBDesired
and amountAMin
:amountBmin
accepts my liquidity addition, if instead the proportion exceeds my range, cancel my transaction"
QUESTION
What does getAmountsOut/getAmountOut and getAmountsIn/getAmountIn exactly do? There isn't an explanation in the Pancakeswap docs, so I'm not sure how could I use it. What's the difference between the two and with the 's' or none?
ANSWER
Answered 2021-Dec-05 at 20:10The difference is that the one with the "s" return the series of outputs resulting from a path
of swaps. Whereas the ones without the "s" return the output for a single swap.
So if I swap along the path ["ETHUSDT", "USDTUSDC"]
then getAmountsOut
will return the USDT output amount from the ETHUSDT swap and the USDC output amount from the "USDTUSDC" swap. The returned value will look like: [usdtAmount, usdcAmount]
.
If I swap "ETHUSDT" then getAmountOut will return usdtAmount
.
The inverse is true for getAmountsIn/getAmountIn.
It's defined here: https://github.com/pancakeswap/pancake-swap-periphery/blob/master/contracts/libraries/PancakeLibrary.sol#L63
QUESTION
I have a Haskell query
function to get latest token price using
https://coinmarketcap.com/api/documentation/v1/#operation/getV1CryptocurrencyQuotesLatest
The function takes token id as arg, say 2010
for ADA.
import Data.Aeson
import Network.HTTP.Req
newtype Rate = Rate Double
query :: Int -> IO (Either Text Rate)
query tokenId =
let
url = https queryPrefix /: "v1" /: "cryptocurrency" /: "quotes" /: "latest"
idParam = "id" =: tokenId
options = standardHeader <> idParam
in
runReq defaultHttpConfig $ do
v <- req GET url NoReqBody jsonResponse options
let responseCode = responseStatusCode v
if isValidHttpResponse responseCode then do
case fromJSON $ responseBody v of
Success x -> pure $ Right x
Error e -> pure $ Left $ pack $ "Error decoding state: " <> e
else
pure $ Left $ pack ("Error with CoinMarketCap query 'Quotes Latest': " <> show responseCode <> ". " <> show (responseStatusMessage v))
The Json output though has "2010" as a key:
{"status":
{"timestamp":"2021-10-24T03:35:01.583Z","error_code":0,"error_message":null,"elapsed":163,"credit_count":1,"notice":null}
,"data":
{"2010":
{"id":2010
,"name":"Cardano"
,"symbol":"ADA"
,"slug":"cardano"
,"num_market_pairs":302,"date_added":"2017-10-01T00:00:00.000Z"
,"tags":["mineable","dpos","pos","platform","research","smart-contracts","staking","binance-smart-chain","cardano-ecosystem"]
,"max_supply":45000000000
,"circulating_supply":32904527668.666
,"total_supply":33250650235.236,"is_active":1
,"platform":null
,"cmc_rank":4
,"is_fiat":0
,"last_updated":"2021-10-24T03:33:31.000Z"
,"quote":
{"USD":
{"price":2.16109553945978
,"volume_24h":2048006882.386299
,"volume_change_24h":-24.06,"percent_change_1h":0.24896227
,"percent_change_24h":0.38920394
,"percent_change_7d":-0.97094597
,"percent_change_30d":-6.13245906
,"percent_change_60d":-21.94246757
,"percent_change_90d":63.56901345
,"market_cap":71109827972.785
,"market_cap_dominance":2.7813
,"fully_diluted_market_cap":97249299275.69,"last_updated":"2021-10-24T03:33:31.000Z"}}}}}
Being that 2010
is an arg to query
, I clearly do not want to drill in as data.2010.quote.USD.price
with something like this:
instance FromJSON Rate where
parseJSON = withObject "Rate" $ \o -> do
dataO <- o .: "data"
_2010O <- dataO .: "2010" -- #############
quoteO <- _2010O .: "quote"
usdO <- quoteO .: "USD"
price <- usdO .: "price"
pure $ Rate price
Question: How can I achieve the flexibility I want? Can I somehow pass in the token id to parseJSON
? Or is there perhaps a Lens-Aeson technique to use a wildcard? ...
ANSWER
Answered 2021-Oct-24 at 16:12I you are completely sure that the object inside "data"
will only ever have a single key, we can take the object, convert it into a list of values, fail if the list is empty or has more than one value, and otherwise continue parsing. Like this:
instance FromJSON Rate where
parseJSON = withObject "Rate" $ \o -> do
Object dataO <- o .: "data" -- we expect an Object
-- get the single value, it should be an Object itself
[Object _2010O] <- pure $ Data.Foldable.toList dataO
quoteO <- _2010O .: "quote"
usdO <- quoteO .: "USD"
price <- usdO .: "price"
pure $ Rate price
When there's no key, more than one key, or the value is not an aeson Object
, the pattern [Object _2010O] <-
fails to match and gives an parsing error through the MonadFail
instance of aeson's Parser
.
We could also be a bit more explicit:
instance FromJSON Rate where
parseJSON = withObject "Rate" $ \o -> do
Object dataO <- o .: "data"
let objects = Data.Foldable.toList dataO
case objects of
[Object _2010O] -> do
quoteO <- _2010O .: "quote"
usdO <- quoteO .: "USD"
price <- usdO .: "price"
pure $ Rate price
[_] -> fail "value is not Object"
_ -> fail "zero or more than one key"
QUESTION
I am trying to learn how to use the ChainlinkClient and I am using their example as well as one for the API that I am trying to uses.
You can see them here on this Gist.
The two contracts in the Gist are deployed on Rinkenby here:
When I call the requestData() method on both contracts they seems to work, the transactions goes through and Link gets taken from the contracts, I am however unable to determine whether the actual data I am requesting from the external APIs gets returned, either by looking in the transaction event or trying to access the value that I am setting.
I am a bit bamboozled at this point, any guidance or suggestions would be greatly appreciated.
ANSWER
Answered 2021-Oct-11 at 16:18Thanks for the flag. The node that was hosting this is deprecated, the article has been updated, and the docs have the latest example.
Please use:
oracle = 0xc57B33452b4F7BB189bB5AfaE9cc4aBa1f7a4FD8;
jobId = "d5270d1c311941d0b08bead21fea7747";
QUESTION
I am new to python/coding and I'm seeking some basic help to pull some elements from what I think is a dictionary. So I am executing the below.
print(data_quote)
Which returns this:
RESPONSE: 218ms OK: [{'id': 1, 'name': 'Bitcoin', 'symbol': 'BTC', 'slug': 'bitcoin', 'num_market_pairs': 9506, 'date_added': '2013-04-28T00:00:00.000Z', 'tags': ['mineable', 'pow', 'sha-256', 'store-of-value', 'state-channels', 'coinbase-ventures-portfolio', 'three-arrows-capital-portfolio', 'polychain-capital-portfolio', 'binance-labs-portfolio', 'arrington-xrp-capital', 'blockchain-capital-portfolio', 'boostvc-portfolio', 'cms-holdings-portfolio', 'dcg-portfolio', 'dragonfly-capital-portfolio', 'electric-capital-portfolio', 'fabric-ventures-portfolio', 'framework-ventures', 'galaxy-digital-portfolio', 'huobi-capital', 'alameda-research-portfolio', 'a16z-portfolio', '1confirmation-portfolio', 'winklevoss-capital', 'usv-portfolio', 'placeholder-ventures-portfolio', 'pantera-capital-portfolio', 'multicoin-capital-portfolio', 'paradigm-xzy-screener'], 'max_supply': 21000000, 'circulating_supply': 18675393, 'total_supply': 18675393, 'platform': None, 'cmc_rank': 1, 'last_updated': '2021-04-06T21:17:02.000Z', 'quote': {'USD': {'price': 58324.48252140573, 'volume_24h': 65699187936.697296, 'percent_change_1h': -0.11815165, 'percent_change_24h': -1.30799467, 'percent_change_7d': -0.86713748, 'percent_change_30d': 16.89536691, 'percent_change_60d': 55.08996724, 'percent_change_90d': 68.97932129, 'market_cap': 1089232632608.8828, 'last_updated': '2021-04-06T21:17:02.000Z'}}}, {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'slug': 'ethereum', 'num_market_pairs': 6188, 'date_added': '2015-08-07T00:00:00.000Z', 'tags': ['mineable', 'pow', 'smart-contracts', 'ethereum', 'coinbase-ventures-portfolio', 'three-arrows-capital-portfolio', 'polychain-capital-portfolio', 'binance-labs-portfolio', 'arrington-xrp-capital', 'blockchain-capital-portfolio', 'boostvc-portfolio', 'cms-holdings-portfolio', 'dcg-portfolio', 'dragonfly-capital-portfolio', 'electric-capital-portfolio', 'fabric-ventures-portfolio', 'framework-ventures', 'hashkey-capital-portfolio', 'kinetic-capital', 'huobi-capital', 'alameda-research-portfolio', 'a16z-portfolio', '1confirmation-portfolio', 'winklevoss-capital', 'usv-portfolio', 'placeholder-ventures-portfolio', 'pantera-capital-portfolio', 'multicoin-capital-portfolio', 'paradigm-xzy-screener'], 'max_supply': None, 'circulating_supply': 115361642.1865, 'total_supply': 115361642.1865, 'platform': None, 'cmc_rank': 2, 'last_updated': '2021-04-06T21:17:02.000Z', 'quote': {'USD': {'price': 2120.1707443094906, 'volume_24h': 29172611149.352947, 'percent_change_1h': -0.1523387, 'percent_change_24h': 0.57727077, 'percent_change_7d': 14.76712255, 'percent_change_30d': 29.55009273, 'percent_change_60d': 24.5531557, 'percent_change_90d': 86.25530334, 'market_cap': 244586378779.31683, 'last_updated': '2021-04-06T21:17:02.000Z'}}}, {'id': 1839, 'name': 'Binance Coin', 'symbol': 'BNB', 'slug': 'binance-coin', 'num_market_pairs': 576, 'date_added': '2017-07-25T00:00:00.000Z', 'tags': ['marketplace', 'centralized-exchange', 'payments', 'binance-smart-chain', 'alameda-research-portfolio', 'multicoin-capital-portfolio'], 'max_supply': 170532785, 'circulating_supply': 154532785, 'total_supply': 170532785, 'platform': None, 'cmc_rank': 3, 'last_updated': '2021-04-06T21:16:17.000Z', 'quote': {'USD': {'price': 405.0598935039566, 'volume_24h': 5135791169.576727, 'percent_change_1h': 2.4766722, 'percent_change_24h': 8.19191755, 'percent_change_7d': 32.6945233, 'percent_change_30d': 75.57514085, 'percent_change_60d': 541.98708005, 'percent_change_90d': 881.50573075, 'market_cap': 62595033434.96982, 'last_updated': '2021-04-06T21:16:17.000Z'}}}, {'id': 52, 'name': 'XRP', 'symbol': 'XRP', 'slug': 'xrp', 'num_market_pairs': 662, 'date_added': '2013-08-04T00:00:00.000Z', 'tags': ['medium-of-exchange', 'enterprise-solutions', 'binance-chain', 'arrington-xrp-capital', 'galaxy-digital-portfolio', 'a16z-portfolio', 'pantera-capital-portfolio'], 'max_supply': 100000000000, 'circulating_supply': 45404028640, 'total_supply': 99990831162, 'platform': None, 'cmc_rank': 4, 'last_updated': '2021-04-06T21:17:03.000Z', 'quote': {'USD': {'price': 1.04733959535835, 'volume_24h': 36929086490.79997, 'percent_change_1h': 3.6474961, 'percent_change_24h': 23.33977412, 'percent_change_7d': 84.65437298, 'percent_change_30d': 127.7463018, 'percent_change_60d': 137.07977162, 'percent_change_90d': 337.68047475, 'market_cap': 47553436983.456535, 'last_updated': '2021-04-06T21:17:03.000Z'}}}, {'id': 825, 'name': 'Tether', 'symbol': 'USDT', 'slug': 'tether', 'num_market_pairs': 11828, 'date_added': '2015-02-25T00:00:00.000Z', 'tags': ['store-of-value', 'payments', 'stablecoin', 'stablecoin-asset-backed', 'solana-ecosystem'], 'max_supply': None, 'circulating_supply': 42990752850.31685, 'total_supply': 43646290993.53494, 'platform': {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'slug': 'ethereum', 'token_address': '0xdac17f958d2ee523a2206206994597c13d831ec7'}, 'cmc_rank': 5, 'last_updated': '2021-04-06T21:16:17.000Z', 'quote': {'USD': {'price': 1.00180954051279, 'volume_24h': 147105163700.08792, 'percent_change_1h': -0.00337412, 'percent_change_24h': 0.13043176, 'percent_change_7d': 0.1191329, 'percent_change_30d': 0.16099888, 'percent_change_60d': 0.16947024, 'percent_change_90d': 0.05326217, 'market_cap': 43068546359.27484, 'last_updated': '2021-04-06T21:16:17.000Z'}}}, {'id': 2010, 'name': 'Cardano', 'symbol': 'ADA', 'slug': 'cardano', 'num_market_pairs': 255, 'date_added': '2017-10-01T00:00:00.000Z', 'tags': ['mineable', 'dpos', 'pos', 'platform', 'research', 'smart-contracts', 'staking', 'binance-chain'], 'max_supply': 45000000000, 'circulating_supply': 31948309440.7478, 'total_supply': 45000000000, 'platform': None, 'cmc_rank': 6, 'last_updated': '2021-04-06T21:16:11.000Z', 'quote': {'USD': {'price': 1.25155454518986, 'volume_24h': 6269725512.213743, 'percent_change_1h': -2.07133508, 'percent_change_24h': 4.42214999, 'percent_change_7d': 2.4917662, 'percent_change_30d': 12.76515356, 'percent_change_60d': 134.01783531, 'percent_change_90d': 325.17673752, 'market_cap': 39985051891.70002, 'last_updated': '2021-04-06T21:16:11.000Z'}}}, {'id': 6636, 'name': 'Polkadot', 'symbol': 'DOT', 'slug': 'polkadot-new', 'num_market_pairs': 175, 'date_added': '2020-08-19T00:00:00.000Z', 'tags': ['substrate', 'polkadot', 'binance-chain', 'polkadot-ecosystem', 'three-arrows-capital-portfolio', 'polychain-capital-portfolio', 'blockchain-capital-portfolio', 'boostvc-portfolio', 'cms-holdings-portfolio', 'coinfund-portfolio', 'fabric-ventures-portfolio', 'fenbushi-capital-portfolio', 'hashkey-capital-portfolio', 'kinetic-capital', '1confirmation-portfolio', 'placeholder-ventures-portfolio', 'pantera-capital-portfolio'], 'max_supply': None, 'circulating_supply': 926243043.5634505, 'total_supply': 1062267157.0176383, 'platform': None, 'cmc_rank': 7, 'last_updated': '2021-04-06T21:17:05.000Z', 'quote': {'USD': {'price': 43.13745049794805, 'volume_24h': 3219936954.166115, 'percent_change_1h': 0.06857841, 'percent_change_24h': -1.95999633, 'percent_change_7d': 27.0018333, 'percent_change_30d': 28.41686344, 'percent_change_60d': 109.63967495, 'percent_change_90d': 338.72895952, 'market_cap': 39955763440.78709, 'last_updated': '2021-04-06T21:17:05.000Z'}}}, {'id': 7083, 'name': 'Uniswap', 'symbol': 'UNI', 'slug': 'uniswap', 'num_market_pairs': 228, 'date_added': '2020-09-17T00:00:00.000Z', 'tags': ['decentralized-exchange', 'defi', 'dao', 'yield-farming', 'amm', 'coinbase-ventures-portfolio', 'three-arrows-capital-portfolio', 'governance', 'blockchain-capital-portfolio', 'defiance-capital', 'alameda-research-portfolio', 'a16z-portfolio', 'pantera-capital-portfolio', 'parafi-capital', 'paradigm-xzy-screener'], 'max_supply': 1000000000, 'circulating_supply': 523256856.47115046, 'total_supply': 1000000000, 'platform': {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'slug': 'ethereum', 'token_address': '0x1f9840a85d5af5bf1d1762f925bdaddc4201f984'}, 'cmc_rank': 8, 'last_updated': '2021-04-06T21:16:11.000Z', 'quote': {'USD': {'price': 31.12928923765244, 'volume_24h': 568914709.7484151, 'percent_change_1h': 0.02767427, 'percent_change_24h': 0.43722838, 'percent_change_7d': 8.51145288, 'percent_change_30d': 0.51900684, 'percent_change_60d': 48.78864152, 'percent_change_90d': 409.23009991, 'market_cap': 16288614030.675232, 'last_updated': '2021-04-06T21:16:11.000Z'}}}, {'id': 2, 'name': 'Litecoin', 'symbol': 'LTC', 'slug': 'litecoin', 'num_market_pairs': 735, 'date_added': '2013-04-28T00:00:00.000Z', 'tags': ['mineable', 'pow', 'scrypt', 'medium-of-exchange', 'binance-chain'], 'max_supply': 84000000, 'circulating_supply': 66752414.51538747, 'total_supply': 66752414.51538747, 'platform': None, 'cmc_rank': 9, 'last_updated': '2021-04-06T21:17:02.000Z', 'quote': {'USD': {'price': 242.9633916548622, 'volume_24h': 9318409785.449207, 'percent_change_1h': 1.58679941, 'percent_change_24h': 11.0925692, 'percent_change_7d': 24.23189386, 'percent_change_30d': 31.49825467, 'percent_change_60d': 60.24127203, 'percent_change_90d': 51.72866252, 'market_cap': 16218393031.809793, 'last_updated': '2021-04-06T21:17:02.000Z'}}}, {'id': 1975, 'name': 'Chainlink', 'symbol': 'LINK', 'slug': 'chainlink', 'num_market_pairs': 489, 'date_added': '2017-09-20T00:00:00.000Z', 'tags': ['platform', 'defi', 'oracles', 'smart-contracts', 'substrate', 'polkadot', 'polkadot-ecosystem', 'solana-ecosystem', 'framework-ventures'], 'max_supply': 1000000000, 'circulating_supply': 417509556.43444455, 'total_supply': 1000000000, 'platform': {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'slug': 'ethereum', 'token_address': '0x514910771af9ca656af840dff83e8264ecf986ca'}, 'cmc_rank': 10, 'last_updated': '2021-04-06T21:16:17.000Z', 'quote': {'USD': {'price': 34.37016617113642, 'volume_24h': 2808495199.288725, 'percent_change_1h': 1.68675913, 'percent_change_24h': 9.05688888, 'percent_change_7d': 22.63094934, 'percent_change_30d': 25.10625714, 'percent_change_60d': 31.84392867, 'percent_change_90d': 116.01508249, 'market_cap': 14349872832.689318, 'last_updated': '2021-04-06T21:16:17.000Z'}}}, {'id': 512, 'name': 'Stellar', 'symbol': 'XLM', 'slug': 'stellar', 'num_market_pairs': 335, 'date_added': '2014-08-05T00:00:00.000Z', 'tags': ['medium-of-exchange', 'enterprise-solutions', 'decentralized-exchange', 'smart-contracts', 'hashkey-capital-portfolio'], 'max_supply': 50001806812, 'circulating_supply': 22785681260.406754, 'total_supply': 50001803396.7887, 'platform': None, 'cmc_rank': 11, 'last_updated': '2021-04-06T21:17:06.000Z', 'quote': {'USD': {'price': 0.54033565169129, 'volume_24h': 5245142768.280184, 'percent_change_1h': 3.37469651, 'percent_change_24h': 7.14744287, 'percent_change_7d': 33.11473896, 'percent_change_30d': 33.55922282, 'percent_change_60d': 55.3151775, 'percent_change_90d': 91.57645886, 'market_cap': 12311915933.0719, 'last_updated': '2021-04-06T21:17:06.000Z'}}}, {'id': 1831, 'name': 'Bitcoin Cash', 'symbol': 'BCH', 'slug': 'bitcoin-cash', 'num_market_pairs': 579, 'date_added': '2017-07-23T00:00:00.000Z', 'tags': ['mineable', 'pow', 'sha-256', 'marketplace', 'enterprise-solutions', 'binance-chain'], 'max_supply': 21000000, 'circulating_supply': 18700881.25, 'total_supply': 18700881.25, 'platform': None, 'cmc_rank': 12, 'last_updated': '2021-04-06T21:16:09.000Z', 'quote': {'USD': {'price': 658.2993698785465, 'volume_24h': 5685814145.115592, 'percent_change_1h': 0.25032514, 'percent_change_24h': 6.63039386, 'percent_change_7d': 24.52915538, 'percent_change_30d': 30.08131641, 'percent_change_60d': 52.01052998, 'percent_change_90d': 52.10446019, 'market_cap': 12310778343.048525, 'last_updated': '2021-04-06T21:16:09.000Z'}}}, {'id': 2416, 'name': 'THETA', 'symbol': 'THETA', 'slug': 'theta', 'num_market_pairs': 51, 'date_added': '2018-01-17T00:00:00.000Z', 'tags': ['media', 'collectibles-nfts', 'content-creation', 'video', 'huobi-capital'], 'max_supply': 1000000000, 'circulating_supply': 1000000000, 'total_supply': 1000000000, 'platform': None, 'cmc_rank': 13, 'last_updated': '2021-04-06T21:17:05.000Z', 'quote': {'USD': {'price': 11.66543045119241, 'volume_24h': 365082525.14074886, 'percent_change_1h': -0.52342705, 'percent_change_24h': -0.62557224, 'percent_change_7d': -10.01162192, 'percent_change_30d': 179.28291648, 'percent_change_60d': 389.39405458, 'percent_change_90d': 456.27518714, 'market_cap': 11665430451.19241, 'last_updated': '2021-04-06T21:17:05.000Z'}}}, {'id': 2280, 'name': 'Filecoin', 'symbol': 'FIL', 'slug': 'filecoin', 'num_market_pairs': 112, 'date_added': '2017-12-13T00:00:00.000Z', 'tags': ['mineable', 'distributed-computing', 'filesharing', 'storage', 'polychain-capital-portfolio', 'blockchain-capital-portfolio', 'boostvc-portfolio', 'dcg-portfolio', 'hashkey-capital-portfolio', 'a16z-portfolio', 'winklevoss-capital', 'pantera-capital-portfolio'], 'max_supply': 2000000000, 'circulating_supply': 64698550, 'total_supply': 64698550, 'platform': None, 'cmc_rank': 14, 'last_updated': '2021-04-06T21:17:04.000Z', 'quote': {'USD': {'price': 166.96838010672514, 'volume_24h': 2475324138.941406, 'percent_change_1h': 0.37024939, 'percent_change_24h': -5.84434356, 'percent_change_7d': 14.1019259, 'percent_change_30d': 312.88250195, 'percent_change_60d': 556.35444044, 'percent_change_90d': 669.89462096, 'market_cap': 10802612088.753962, 'last_updated': '2021-04-06T21:17:04.000Z'}}}, {'id': 3408, 'name': 'USD Coin', 'symbol': 'USDC', 'slug': 'usd-coin', 'num_market_pairs': 886, 'date_added': '2018-10-08T00:00:00.000Z', 'tags': ['medium-of-exchange', 'stablecoin', 'stablecoin-asset-backed'], 'max_supply': None, 'circulating_supply': 10701284553.25657, 'total_supply': 10935302496.29955, 'platform': {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'slug': 'ethereum', 'token_address': '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'}, 'cmc_rank': 15, 'last_updated': '2021-04-06T21:17:05.000Z', 'quote': {'USD': {'price': 1.0016702670119, 'volume_24h': 1492667925.6445038, 'percent_change_1h': -0.00623742, 'percent_change_24h': 0.12119331, 'percent_change_7d': 0.13764092, 'percent_change_30d': 0.15185142, 'percent_change_60d': 0.18442668, 'percent_change_90d': 0.19390034, 'market_cap': 10719158555.83083, 'last_updated': '2021-04-06T21:17:05.000Z'}}}, {'id': 1958, 'name': 'TRON', 'symbol': 'TRX', 'slug': 'tron', 'num_market_pairs': 511, 'date_added': '2017-09-13T00:00:00.000Z', 'tags': ['media', 'payments'], 'max_supply': None, 'circulating_supply': 71659657369.49, 'total_supply': 100850743811.662, 'platform': None, 'cmc_rank': 16, 'last_updated': '2021-04-06T21:16:11.000Z', 'quote': {'USD': {'price': 0.12023377395961, 'volume_24h': 10666497577.898384, 'percent_change_1h': -1.38280983, 'percent_change_24h': -18.19901679, 'percent_change_7d': 83.5388578, 'percent_change_30d': 137.73408779, 'percent_change_60d': 235.99926728, 'percent_change_90d': 311.31508806, 'market_cap': 8615911046.186363, 'last_updated': '2021-04-06T21:16:11.000Z'}}}, {'id': 4256, 'name': 'Klaytn', 'symbol': 'KLAY', 'slug': 'klaytn', 'num_market_pairs': 31, 'date_added': '2020-03-30T00:00:00.000Z', 'tags': ['platform', 'enterprise-solutions'], 'max_supply': None, 'circulating_supply': 2448059130.2, 'total_supply': 10527368819.2, 'platform': None, 'cmc_rank': 17, 'last_updated': '2021-04-06T21:17:03.000Z', 'quote': {'USD': {'price': 3.43708080302498, 'volume_24h': 398613006.598883, 'percent_change_1h': -0.18651522, 'percent_change_24h': 3.98616401, 'percent_change_7d': -17.95950702, 'percent_change_30d': 116.85588005, 'percent_change_60d': 514.06987053, 'percent_change_90d': 650.84850594, 'market_cap': 8414177041.08045, 'last_updated': '2021-04-06T21:17:03.000Z'}}}, {'id': 3717, 'name': 'Wrapped Bitcoin', 'symbol': 'WBTC', 'slug': 'wrapped-bitcoin', 'num_market_pairs': 118, 'date_added': '2019-01-30T00:00:00.000Z', 'tags': ['medium-of-exchange', 'defi', 'stablecoin', 'stablecoin-asset-backed', 'wrapped-tokens'], 'max_supply': None, 'circulating_supply': 141602.84791701, 'total_supply': 141602.84791701, 'platform': {'id': 1027, 'name': 'Ethereum', 'symbol': 'ETH', 'slug': 'ethereum', 'token_address': '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'}, 'cmc_rank': 18, 'last_updated': '2021-04-06T21:17:07.000Z', 'quote': {'USD': {'price': 58268.692973170684, 'volume_24h': 119328797.86432272, 'percent_change_1h': 0.163808, 'percent_change_24h': -0.93183652, 'percent_change_7d': -1.03181988, 'percent_change_30d': 16.24982113, 'percent_change_60d': 54.17252068, 'percent_change_90d': 68.24914656, 'market_cap': 8251012869.402837, 'last_updated': '2021-04-06T21:17:07.000Z'}}}, {'id': 74, 'name': 'Dogecoin', 'symbol': 'DOGE', 'slug': 'dogecoin', 'num_market_pairs': 312, 'date_added': '2013-12-15T00:00:00.000Z', 'tags': ['mineable', 'pow', 'scrypt', 'medium-of-exchange', 'memes', 'payments'], 'max_supply': None, 'circulating_supply': 129072700574.95102, 'total_supply': 129072700574.95102, 'platform': None, 'cmc_rank': 19, 'last_updated': '2021-04-06T21:17:03.000Z', 'quote': {'USD': {'price': 0.06148653027568, 'volume_24h': 2501156924.1030483, 'percent_change_1h': -0.0267709, 'percent_change_24h': 5.51264765, 'percent_change_7d': 14.18176769, 'percent_change_30d': 20.92946895, 'percent_change_60d': 33.56381468, 'percent_change_90d': 531.47468079, 'market_cap': 7936232511.665504, 'last_updated': '2021-04-06T21:17:03.000Z'}}}, {'id': 3077, 'name': 'VeChain', 'symbol': 'VET', 'slug': 'vechain', 'num_market_pairs': 122, 'date_added': '2017-08-22T00:00:00.000Z', 'tags': ['logistics', 'data-provenance', 'iot', 'smart-contracts', 'fenbushi-capital-portfolio'], 'max_supply': 86712634466, 'circulating_supply': 64315576989, 'total_supply': 86712634466, 'platform': None, 'cmc_rank': 20, 'last_updated': '2021-04-06T21:17:02.000Z', 'quote': {'USD': {'price': 0.113128687309, 'volume_24h': 1584710073.9041638, 'percent_change_1h': 2.45566548, 'percent_change_24h': 7.02819179, 'percent_change_7d': 26.82127317, 'percent_change_30d': 104.43460758, 'percent_change_60d': 271.60156874, 'percent_change_90d': 294.80711983, 'market_cap': 7275936798.286496, 'last_updated': '2021-04-06T21:17:02.000Z'}}}]
And I have searched up and down stackoverflow and other websites, including coinmarketcap API documentation (here for referece: https://coinmarketcap.com/api/documentation/v1/) but I can't figure out how to get 'names' and 'price' from that data_quote. To me this looks like a dictionary but when I print type it returns this (see below) which throws me entirely off.
I've tried something like this:
newlist = [d['name'] for d in data_quote]
print(newlist)
But I get this:
TypeError: 'Response' object is not iterable
ANSWER
Answered 2021-Apr-07 at 16:35The response basically looks like a list of dicts. So to extract names (or other keys) you can just do a list comprehension:
[d['name'] for d in data_quote]
QUESTION
This answer about upgradability suggests that at some point you should delete access keys to the account containing a smart contract: How do you upgrade NEAR smart contracts?.
It makes sense that a smart contract should be "frozen" at some point, and you want to give its users confidence that it will not be changed. But what about contract rewards and other funds belonging to the contract account? How would the original owner get access to that if keys are deleted?
ANSWER
Answered 2021-Mar-22 at 13:51But what about contract rewards and other funds belonging to the contract account? How would the original owner get access to that if keys are deleted?
The contract should be implemented in such a way that would allow certain operations.
Let's take a lockup contract as an example. This contract has a single owner, and the funds are locked for a certain amount of time, and the contract only provides certain methods to be called and guarded with the specific logic:
- As an owner, I can delegate (stake) my tokens to staking pools while I still cannot arbitrary transfer the tokens
- As an owner, I can withdraw the rewards from the staking pool through the lockup contract, and transfer those to an arbitrary account
- Once the lockup time is over, as an owner, I can call
add_full_access_key
function, and thus gain full access over the account, and even delete it after that (transferring all the tokens to some other account).
All that is explicitly implemented on the contract level, and easy to review, and given there is no other AccessKey on the lockup contract, we can be sure that there is no other way to interfere with the contract logic.
QUESTION
I want to use web3.py and infura.io to listen for Uniswap factory events however I am not too sure where to go about doing so.
Here is a link: https://uniswap.org/docs/v2/smart-contracts/factory/
More specifically I want to listen for the PairCreated
event.
ANSWER
Answered 2020-Jun-25 at 08:22Here is rough guide
Get ABI for Uniswap contract
Create a web3.py contract object
You can use
web3.eth.getLogs()
to query events over past block rangeYou cannot query all events once, because there are so many events and Infura would time out. Instead you need to query events carefully over a block range slices.
Here is some old code which may or may not work with the latest web3.py versions
https://github.com/TokenMarketNet/sto/blob/master/sto/ethereum/scanner.py#L153
If you want a real time scanner you can listed to events over a WebSocket connection as they happen:
https://web3py.readthedocs.io/en/stable/filters.html#asynchronous-filter-polling
QUESTION
For some TRON contracts i am not able to get ABI. Eg using https://developers.tron.network/reference#smart-contracts for this one:
contract - TQn9Y2khEsLJW1ChVWFMSMeRDow5KcbLSE
curl --request POST \
--url https://api.trongrid.io/wallet/getcontract \
--header 'content-type: application/json' \
--data '{"value":"41a2726afbecbd8e936000ed684cef5e2f5cf43008","visible":false}'
it does not return ABI. Why it does not return? how to get this ABI not using tronscan?
ANSWER
Answered 2020-Oct-20 at 10:57This is a contract created by another contract. So there's no chance for the developer to set an ABI.
You should refer to the creator contract's code.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install smart-contracts
npm ci
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page