SmartContractsListGet()
Last updated
Last updated
Before calling the function make sure you have the Connector object initialized.
Field
Type
Description
Address
string
Base58 ed25519 Smart Contract Address
Offset
long
Offset enables you to search 10 Transactions later or any given number
Limit
long
Limit Amount per request
SmartContractsListGet("Input here Base58 Deployer PublicKey Key",0,10);
Return value of function: SmartContractsListGetResult
Connector connect_ = new Connector("95.111.224.219", 9091);
NodeApi.SmartContractsListGetResult SmartContractList = connect_.SmartContractsListGet("4SFfA1S2xfA3BdgkTn2tK14yDhLuD11RVz78kqx35jct",0,10);
Console.WriteLine(SmartContractList);
Connect_ = Connector("165.22.212.253:9090")
print(Connect_.SmartContractsListGet("EoPibFsGPE4xqXH2tYTBQUeJqSMMFvCZUdqAW9Bnh3nd",0,10))
var connect_ = new Connector("194.163.152.177", 9091);
connect_.SmartContractsListGet("EoPibFsGPE4xqXH2tYTBQUeJqSMMFvCZUdqAW9Bnh3nd",0,2).then((res) => {connect_.Close();console.log(res); });
Return value of function: SmartContractsListGetResult
Output is printed via ObjectDumper
{SmartContractsListGetResult}
Status: {APIResponse}
Code: 0
Message: "Success: "
Count: 15
SmartContractsList: ...
{SmartContract}
Address: ...
Deployer: ...
SmartContractDeploy: {SmartContractDeploy}
SourceCode: "\nimport com.credits.scapi.v0.BasicStandard;\nimport com.credits.scapi.v0.SmartContract;\n\nimport java.math.BigDecimal;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Optional;\n\nimport static java.math.BigDecimal.ROUND_DOWN;\nimport static java.math.BigDecimal.ZERO;\n\npublic class TokenLINS extends SmartContract implements BasicStandard {\n\n private final String owner;\n private final BigDecimal tokenCost;\n private final int decimal;\n HashMap<String, BigDecimal> balances;\n private String name;\n private String symbol;\n private BigDecimal totalCoins;\n private HashMap<String, Map<String, BigDecimal>> allowed;\n private boolean frozen;\n\n public TokenLINS() {\n super();\n name = \"LIFE_INS\";\n symbol = \"LINS\";\n decimal = 2;\n tokenCost = new BigDecimal(0).setScale(decimal, ROUND_DOWN);\n totalCoins = new BigDecimal(100000).setScale(decimal, ROUND_DOWN);\n owner = initiator;\n allowed = new HashMap<>();\n balances = new HashMap<>();\n balances.put(owner, new BigDecimal(100000L).setScale(decimal, ROUND_DOWN));\n }\n\n @Override\n public int getDecimal() {\n return decimal;\n }\n\n @Override\n public boolean setFrozen(boolean isFrozen) {\n if (!initiator.equals(owner)) {\n throw new RuntimeException(\"unable change frozen state! The wallet \" + initiator + \" is not owner\");\n }\n this.frozen = isFrozen;\n return true;\n }\n\n @Override\n public String getName() {\n return name;\n }\n\n @Override\n public String getSymbol() {\n return symbol;\n }\n\n @Override\n public String totalSupply() {\n return totalCoins.toString();\n }\n\n @Override\n public String balanceOf(String owner) {\n return getTokensBalance(owner).toString();\n }\n\n @Override\n public String allowance(String owner, String spender) {\n if (allowed.get(owner) == null) {\n return \"0\";\n }\n BigDecimal amount = allowed.get(owner).get(spender);\n return amount != null ? amount.toString() : \"0\";\n }\n\n @Override\n public boolean transfer(String to, String amount) {\n contractIsNotFrozen();\n if (!to.equals(initiator)) {\n BigDecimal decimalAmount = toBigDecimal(amount);\n BigDecimal sourceBalance = getTokensBalance(initiator);\n BigDecimal targetTokensBalance = getTokensBalance(to);\n if (sourceBalance.compareTo(decimalAmount) < 0) {\n throw new RuntimeException(\"the wallet \" + initiator + \" doesn\'t have enough tokens to transfer\");\n }\n balances.put(initiator, sourceBalance.subtract(decimalAmount));\n balances.put(to, targetTokensBalance.add(decimalAmount));\n }\n return true;\n }\n\n @Override\n public boolean transferFrom(String from, String to, String amount) {\n contractIsNotFrozen();\n\n if (!from.equals(to)) {\n BigDecimal sourceBalance = getTokensBalance(from);\n BigDecimal targetTokensBalance = getTokensBalance(to);\n BigDecimal decimalAmount = toBigDecimal(amount);\n if (sourceBalance.compareTo(decimalAmount) < 0)\n throw new RuntimeException(\"unable transfer tokens! The balance of \" + from + \" less then \" + amount);\n\n Map<String, BigDecimal> spender = allowed.get(from);\n if (spender == null || !spender.containsKey(initiator))\n throw new RuntimeException(\"unable transfer tokens! The wallet \" + from + \" not allow transfer tokens for \" + to);\n\n BigDecimal allowTokens = spender.get(initiator);\n if (allowTokens.compareTo(decimalAmount) < 0) {\n throw new RuntimeException(\"unable transfer tokens! Not enough allowed tokens. For the wallet \" + initiator + \" allow only \" + allowTokens + \" tokens\");\n }\n\n spender.put(initiator, allowTokens.subtract(decimalAmount));\n balances.put(from, sourceBalance.subtract(decimalAmount));\n balances.put(to, targetTokensBalance.add(decimalAmount));\n }\n return true;\n }\n\n @Override\n public void approve(String spender, String amount) {\n BigDecimal decimalAmount = toBigDecimal(amount);\n Map<String, BigDecimal> initiatorSpenders = allowed.get(initiator);\n if (initiatorSpenders == null) {\n Map<String, BigDecimal> newSpender = new HashMap<>();\n newSpender.put(spender, decimalAmount);\n allowed.put(initiator, newSpender);\n } else {\n BigDecimal spenderAmount = initiatorSpenders.get(spender);\n initiatorSpenders.put(spender, spenderAmount == null ? decimalAmount : spenderAmount.add(decimalAmount));\n }\n }\n\n @Override\n public boolean burn(String amount) {\n contractIsNotFrozen();\n BigDecimal decimalAmount = toBigDecimal(amount);\n if (!initiator.equals(owner))\n throw new RuntimeException(\"can not burn tokens! The wallet \" + initiator + \" is not owner\");\n if (totalCoins.compareTo(decimalAmount) < 0) totalCoins = ZERO.setScale(decimal, ROUND_DOWN);\n else totalCoins = totalCoins.subtract(decimalAmount);\n return true;\n }\n\n public void payable(String amount, String currency) {\n contractIsNotFrozen();\n BigDecimal decimalAmount = toBigDecimal(amount);\n if (totalCoins.compareTo(decimalAmount) < 0) throw new RuntimeException(\"not enough tokes to buy\");\n balances.put(initiator, Optional.ofNullable(balances.get(initiator)).orElse(ZERO).add(decimalAmount));\n totalCoins = totalCoins.subtract(decimalAmount);\n }\n\n private void contractIsNotFrozen() {\n if (frozen) throw new RuntimeException(\"unavailable action! The smart-contract is frozen\");\n }\n\n private BigDecimal toBigDecimal(String stringValue) {\n return new BigDecimal(stringValue).setScale(decimal, ROUND_DOWN);\n }\n\n private BigDecimal getTokensBalance(String address) {\n return Optional.ofNullable(balances.get(address)).orElseGet(() -> {\n balances.put(address, ZERO.setScale(decimal, ROUND_DOWN));\n return ZERO.setScale(decimal, ROUND_DOWN);\n });\n }\n}\n\n\n\n\n\n"
ByteCodeObjects: ...
HashState: ""
TokenStandard: 0
ObjectState: ...
CreateTime: 1556119477499
TransactionsCount: 4
{SmartContract}
Address: ...
Deployer: ...
SmartContractDeploy: {SmartContractDeploy}
SourceCode: "\nimport com.credits.scapi.v0.BasicStandard;\nimport com.credits.scapi.v0.SmartContract;\n\nimport java.math.BigDecimal;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Optional;\n\nimport static java.math.BigDecimal.ROUND_DOWN;\nimport static java.math.BigDecimal.ZERO;\n\npublic class TokenMR extends SmartContract implements BasicStandard {\n\n private final String owner;\n private final BigDecimal tokenCost;\n private final int decimal;\n HashMap<String, BigDecimal> balances;\n private String name;\n private String symbol;\n private BigDecimal totalCoins;\n private HashMap<String, Map<String, BigDecimal>> allowed;\n private boolean frozen;\n\n public TokenMR() {\n super();\n name = \"MIRINE\";\n symbol = \"MR\";\n decimal = 6;\n tokenCost = new BigDecimal(0).setScale(decimal, ROUND_DOWN);\n totalCoins = new BigDecimal(1000000).setScale(decimal, ROUND_DOWN);\n owner = initiator;\n allowed = new HashMap<>();\n balances = new HashMap<>();\n balances.put(owner, new BigDecimal(1000000L).setScale(decimal, ROUND_DOWN));\n }\n\n @Override\n public int getDecimal() {\n return decimal;\n }\n\n @Override\n public boolean setFrozen(boolean isFrozen) {\n if (!initiator.equals(owner)) {\n throw new RuntimeException(\"unable change frozen state! The wallet \" + initiator + \" is not owner\");\n }\n this.frozen = isFrozen;\n return true;\n }\n\n @Override\n public String getName() {\n return name;\n }\n\n @Override\n public String getSymbol() {\n return symbol;\n }\n\n @Override\n public String totalSupply() {\n return totalCoins.toString();\n }\n\n @Override\n public String balanceOf(String owner) {\n return getTokensBalance(owner).toString();\n }\n\n @Override\n public String allowance(String owner, String spender) {\n if (allowed.get(owner) == null) {\n return \"0\";\n }\n BigDecimal amount = allowed.get(owner).get(spender);\n return amount != null ? amount.toString() : \"0\";\n }\n\n @Override\n public boolean transfer(String to, String amount) {\n contractIsNotFrozen();\n if (!to.equals(initiator)) {\n BigDecimal decimalAmount = toBigDecimal(amount);\n BigDecimal sourceBalance = getTokensBalance(initiator);\n BigDecimal targetTokensBalance = getTokensBalance(to);\n if (sourceBalance.compareTo(decimalAmount) < 0) {\n throw new RuntimeException(\"the wallet \" + initiator + \" doesn\'t have enough tokens to transfer\");\n }\n balances.put(initiator, sourceBalance.subtract(decimalAmount));\n balances.put(to, targetTokensBalance.add(decimalAmount));\n }\n return true;\n }\n\n @Override\n public boolean transferFrom(String from, String to, String amount) {\n contractIsNotFrozen();\n\n if (!from.equals(to)) {\n BigDecimal sourceBalance = getTokensBalance(from);\n BigDecimal targetTokensBalance = getTokensBalance(to);\n BigDecimal decimalAmount = toBigDecimal(amount);\n if (sourceBalance.compareTo(decimalAmount) < 0)\n throw new RuntimeException(\"unable transfer tokens! The balance of \" + from + \" less then \" + amount);\n\n Map<String, BigDecimal> spender = allowed.get(from);\n if (spender == null || !spender.containsKey(initiator))\n throw new RuntimeException(\"unable transfer tokens! The wallet \" + from + \" not allow transfer tokens for \" + to);\n\n BigDecimal allowTokens = spender.get(initiator);\n if (allowTokens.compareTo(decimalAmount) < 0) {\n throw new RuntimeException(\"unable transfer tokens! Not enough allowed tokens. For the wallet \" + initiator + \" allow only \" + allowTokens + \" tokens\");\n }\n\n spender.put(initiator, allowTokens.subtract(decimalAmount));\n balances.put(from, sourceBalance.subtract(decimalAmount));\n balances.put(to, targetTokensBalance.add(decimalAmount));\n }\n return true;\n }\n\n @Override\n public void approve(String spender, String amount) {\n BigDecimal decimalAmount = toBigDecimal(amount);\n Map<String, BigDecimal> initiatorSpenders = allowed.get(initiator);\n if (initiatorSpenders == null) {\n Map<String, BigDecimal> newSpender = new HashMap<>();\n newSpender.put(spender, decimalAmount);\n allowed.put(initiator, newSpender);\n } else {\n BigDecimal spenderAmount = initiatorSpenders.get(spender);\n initiatorSpenders.put(spender, spenderAmount == null ? decimalAmount : spenderAmount.add(decimalAmount));\n }\n }\n\n @Override\n public boolean burn(String amount) {\n contractIsNotFrozen();\n BigDecimal decimalAmount = toBigDecimal(amount);\n if (!initiator.equals(owner))\n throw new RuntimeException(\"can not burn tokens! The wallet \" + initiator + \" is not owner\");\n if (totalCoins.compareTo(decimalAmount) < 0) totalCoins = ZERO.setScale(decimal, ROUND_DOWN);\n else totalCoins = totalCoins.subtract(decimalAmount);\n return true;\n }\n\n public void payable(String amount, String currency) {\n contractIsNotFrozen();\n BigDecimal decimalAmount = toBigDecimal(amount);\n if (totalCoins.compareTo(decimalAmount) < 0) throw new RuntimeException(\"not enough tokes to buy\");\n balances.put(initiator, Optional.ofNullable(balances.get(initiator)).orElse(ZERO).add(decimalAmount));\n totalCoins = totalCoins.subtract(decimalAmount);\n }\n\n private void contractIsNotFrozen() {\n if (frozen) throw new RuntimeException(\"unavailable action! The smart-contract is frozen\");\n }\n\n private BigDecimal toBigDecimal(String stringValue) {\n return new BigDecimal(stringValue).setScale(decimal, ROUND_DOWN);\n }\n\n private BigDecimal getTokensBalance(String address) {\n return Optional.ofNullable(balances.get(address)).orElseGet(() -> {\n balances.put(address, ZERO.setScale(decimal, ROUND_DOWN));\n return ZERO.setScale(decimal, ROUND_DOWN);\n });\n }\n}"
ByteCodeObjects: ...
HashState: ""
TokenStandard: 0
ObjectState: ...
CreateTime: 1556787820388
TransactionsCount: 8