This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from iconservice import * | |
TAG = 'SampleCrowdSale' | |
class SampleCrowdSale(IconScoreBase): | |
def __init__(self, db: IconScoreDatabase) -> None: | |
super().__init__(db) | |
def on_install(self) -> None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from iconservice import * | |
#Only package allowed to import is iconservice. You can also write up your own classes and then use it by importing it. | |
TAG = 'SampleCrowdsale' #TAG is basically the same as your main Class name. | |
# An interface of token to give a reward to anyone who contributes | |
class TokenInterface(InterfaceScore): | |
@interface | |
def transfer(self, _to: Address, _value: int, _data: bytes=None): | |
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from iconsdk.exception import JSONRPCException | |
from iconsdk.libs.in_memory_zip import gen_deploy_data_content | |
from iconsdk.icon_service import IconService | |
from iconsdk.providers.http_provider import HTTPProvider | |
from iconsdk.builder.transaction_builder import CallTransactionBuilder, TransactionBuilder, DeployTransactionBuilder | |
from iconsdk.builder.call_builder import CallBuilder | |
from iconsdk.signed_transaction import SignedTransaction | |
from iconsdk.wallet.wallet import KeyWallet | |
from iconsdk.utils.convert_type import convert_hex_str_to_int | |
from repeater import retry |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Uncommnet the line you want to use | |
# Mainnet | NID = 1 | |
# icon_service = IconService(HTTPProvider("https://ctz.solidwallet.io", 1)) | |
# Euljiro | NID = 2 | |
# icon_service = IconService(HTTPProvider("https://test-ctz.solidwallet.io",2)) | |
# Yeouido | NID = 3 | |
icon_service = IconService(HTTPProvider("https://bicon.net.solidwallet.io", 3)) | |
# Pagoda | NID = 80 | |
# icon_service = IconService(HTTPProvider("https://zicon.net.solidwallet.io", 80)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Generates a wallet | |
wallet = KeyWallet.create() | |
# Stores a key store file on the file path with password - abcd1234* | |
file_path = "./test/test_keystore" | |
wallet.store(file_path, "abcd1234*") | |
# Loads a wallet from a keystore file | |
wallet = KeyWallet.load(file_path, "abcd1234*") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GOVERNANCE_ADDRESS = "cx0000000000000000000000000000000000000000" | |
#Deploy parameters are defined in the SCORE in on_install method | |
DEPLOY_PARAMS = { | |
"_fundingGoalInIcx": "0x64", | |
"_tokenScore": "cx5afaf001f490f494ddeba5bcf4dd05fa47df7589", | |
"_durationInBlocks": "0x32" } | |
deploy_transaction = DeployTransactionBuilder()\ | |
.from_(wallet.get_address())\ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tx_result = icon_service.get_transaction_result(tx_hash) | |
tx_result | |
#This is the result displayed in the Jupyter Notebook | |
{'txHash': '0x724a5c1828464a27239fea7eefc41edab3796c792d84d29f5281a83791498be6', | |
'blockHeight': 37802, | |
'blockHash': '0x73080fadb4a3f44bce2bf406802cbbc01451838c2997dfd3d7c4e61620538de2', | |
'txIndex': 0, | |
'to': 'cx0000000000000000000000000000000000000000', | |
'scoreAddress': 'cxf11414ea548ae2d8eac40b5d488212c139718264', # <- This is the SCORE Address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#if params; define as dictionary as in the case of DEPLOY_PARAMS | |
params = {} | |
# Enters transaction information. | |
call_transaction = CallTransactionBuilder()\ | |
.from_(wallet.get_address())\ | |
.to(SCORE_ADDRESS) \ | |
.nid(NID) \ | |
.nonce(100) \ | |
.value(1000000000) \ # only required if ICX is to be sent |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Returns block information by block height | |
block = icon_service.get_block(1000) | |
# Returns block information by block hash | |
block = icon_service.get_block("0x000...000") | |
# Returns the last block information | |
block = icon_service.get_block("latest") | |
# Returns the balance of the account of given address |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
/// @title Hello World Smart Contract | |
/// @author Prajwol Gyawali | |
contract HelloWorld { | |
uint256 no; |
OlderNewer