SmartContractGet()
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
SmartContractGet("Input here Base58 Smart Contract Key");
Return value of function: SmartContractGetResult
Connector connect_ = new Connector("95.111.224.219", 9091);
NodeApi.SmartContractGetResult SmartContract = connect_.SmartContractGet("4SFfA1S2xfA3BdgkTn2tK14yDhLuD11RVz78kqx35jct");
Console.WriteLine(SmartContract);
Connect_ = Connector("165.22.212.253:9090")
print(Connect_.SmartContractGet("12DHXQ8rzYUawD6VSD6WuVaTQ4uen7fStWsTmZASnDv1"))
var connect_ = new Connector("194.163.152.177", 9091);
connect_.SmartContractGet("12DHXQ8rzYUawD6VSD6WuVaTQ4uen7fStWsTmZASnDv1").then((res) => {connect_.Close();console.log(res); });
Return value of function: SmartContractGetResult
Output is printed via ObjectDumper
{SmartContractGetResult}
Status: {APIResponse}
Code: 0
Message: "Success: "
SmartContract: {SmartContract}
Address: ...
Deployer: ...
SmartContractDeploy: {SmartContractDeploy}
SourceCode: "\nimport java.math.BigDecimal;\nimport java.util.HashMap;\nimport java.util.Map;\nimport java.util.Optional;\n\nimport com.credits.scapi.annotations.*;\nimport com.credits.scapi.v0.*;\n\nimport static java.math.BigDecimal.ROUND_FLOOR;\nimport static java.math.BigDecimal.ZERO;\n\npublic class TokenSRG extends SmartContract implements ExtensionStandard {\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 TokenSRG() {\n super();\n name = \"SERGE\";\n symbol = \"SRG\";\n decimal = 2;\n tokenCost = new BigDecimal(0).setScale(decimal, ROUND_FLOOR);\n totalCoins = new BigDecimal(1000000).setScale(decimal, ROUND_FLOOR);\n owner = initiator;\n allowed = new HashMap<>();\n balances = new HashMap<>();\n balances.put(owner, new BigDecimal(1000000L).setScale(decimal, ROUND_FLOOR));\n }\n\n @Override\n public int getDecimal() {\n return decimal;\n }\n\n @Override\n public void register() {\n balances.putIfAbsent(initiator, ZERO.setScale(decimal, ROUND_FLOOR));\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(targetTokensBalance == null)\n {\n targetTokensBalance = new BigDecimal(0).setScale(decimal, ROUND_FLOOR);\n }\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 if(targetTokensBalance == null)\n {\n targetTokensBalance = new BigDecimal(0).setScale(decimal, ROUND_FLOOR);\n }\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 initiatorIsRegistered();\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;\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 @Override\n public boolean buyTokens(String amount) {\n return false;\n }\n\n private void contractIsNotFrozen() {\n if (frozen) throw new RuntimeException(\"unavailable action! The smart-contract is frozen\");\n }\n\n private void initiatorIsRegistered() {\n if (!balances.containsKey(initiator))\n throw new RuntimeException(\"unavailable action! The wallet \" + initiator + \" is not registered\");\n }\n\n private BigDecimal toBigDecimal(String stringValue) {\n return new BigDecimal(stringValue).setScale(decimal, ROUND_FLOOR);\n }\n\n private BigDecimal getTokensBalance(String address) {\n return balances.get(address);\n }\n}\n"
ByteCodeObjects: ...
HashState: ""
TokenStandard: 0
ObjectState: ...
CreateTime: 1590418368185
TransactionsCount: 4