SCORE Interaction

Jupyter Notebook for ICON Environment

As a SCORE developer, using tbears for SCORE deploy,update process and making a transaction call is a bit cumbersome. So to make the whole process smooth, SCORE can be handled with a Jupyter Notebook approach where we will be using Python SDK for each operation in different cell.
We have made a template and all you will have to do is update some parameters to the SDK and execute the cell to perform the operation. This makes us get rid of tbears cli commands hassle while interacting with SCORE.
Before proceeding ahead make sure the prerequisites are already installed.

Cloning the project

You can get the project repo from Github
Run command:-
1
$ git clone https://github.com/OpenDevICON/opendevicon.git
Copied!
Open Jupyter Notebook file using command:-
1
$ cd opendevicon
2
$ jupyter-notebook
Copied!
Now you can see a Jupyter instance running in your browser
Click on SCORE.ipnyb file which will be our main Jupyter Notebook file
If you are new to Jupyter Notebook, read the article to be familiar with usage of Jupyter Notebook

Setting up environment

Before we move on to using the SDK we first need to initialize our environment.

Importing packages

All the necessary packages required for using SDK must be imported.
1
from iconsdk.exception import JSONRPCException
2
from iconsdk.libs.in_memory_zip import gen_deploy_data_content
3
from iconsdk.icon_service import IconService
4
from iconsdk.providers.http_provider import HTTPProvider
5
from iconsdk.builder.transaction_builder import CallTransactionBuilder, TransactionBuilder, DeployTransactionBuilder
6
from iconsdk.builder.call_builder import CallBuilder
7
from iconsdk.signed_transaction import SignedTransaction
8
from iconsdk.wallet.wallet import KeyWallet
9
from iconsdk.utils.convert_type import convert_hex_str_to_int
10
from repeater import retry
11
import requests
12
import json
13
import pickle
14
import csv
15
import os
Copied!
For error msg like package not found
Run command:-
1
$ pip install <package-name>
Copied!

Setting up URL

Create an IconService instance and set a provider. The HTTPProvider takes one of the following URL where the server can be found. For this documentation we will be using Yeouido tesnet.
1
# Mainnet
2
# icon_service = IconService(HTTPProvider("https://ctz.solidwallet.io", 3))
3
# Euljiro
4
# icon_service = IconService(HTTPProvider("https://test-ctz.solidwallet.io",3))
5
# Yeouido
6
icon_service = IconService(HTTPProvider("https://bicon.net.solidwallet.io", 3))
7
# Pagoda
8
# icon_service = IconService(HTTPProvider("https://zicon.net.solidwallet.io", 3))
9
# Custom
10
# icon_service = IconService(HTTPProvider("http://54.186.60.134:9000/", 3))
Copied!

Setting up NID

Netword ID for Yeoido tesnet is 3.
1
# Mainnet
2
# NID = 1
3
# Euljiro Testnet
4
# NID = 2
5
# Yeouido Testnet // Tbears
6
NID = 3
7
# Pagoda Testnet
8
# NID = 80
Copied!

Creating wallets

We will create two wallets, one for deploying SCORE and other for placing bet.
1
deployer_wallet = KeyWallet.create()
2
print("address: ", deployer_wallet.get_address())
3
caller_wallet = KeyWallet.create()
4
print("address: ", caller_wallet.get_address())
Copied!
Go to ibriz-faucet to receive test ICXs in your wallets.
Now we are all set to use the SDK in Jupyter Notebook. You can get the official documentation of PythonSDK for ICON here.
Last modified 1yr ago