diff --git a/EGLDSender.py b/EGLDSender.py
index 6b63c86..fc1b1b7 100644
--- a/EGLDSender.py
+++ b/EGLDSender.py
@@ -43,13 +43,27 @@
# Get the data message
data = " ".join([str(item) for item in args.data])
+# ---------------------------------------------------------------- #
+# CONSTANTS
+# ---------------------------------------------------------------- #
+
+config_network = {
+ "mainnet": {"chainID": "1", "proxy": ""},
+ "devnet": {"chainID": "D", "proxy": "devnet-"},
+ "testnet": {"chainID": "T", "proxy": "testnet-"}
+}
+
+CHAIN = "mainnet"
+CHAIN_ID = config_network[CHAIN]["chainID"]
+PROXY = config_network[CHAIN]["proxy"]
+
# ---------------------------------------------------------------- #
# MAIN EGLD FUNCTION
# ---------------------------------------------------------------- #
def sendEGLD(owner, owner_on_network, receiver, amount, signer):
payment = TokenPayment.egld_from_amount(amount)
- config = DefaultTransactionBuildersConfiguration(chain_id="1")
+ config = DefaultTransactionBuildersConfiguration(chain_id=CHAIN_ID)
builder = EGLDTransferBuilder(
config=config,
@@ -79,7 +93,7 @@ def sendEGLD(owner, owner_on_network, receiver, amount, signer):
pubkey = bytes.fromhex(pem.public_key.hex())
owner = Address(pubkey, "erd")
-provider = ProxyNetworkProvider("https://gateway.multiversx.com")
+provider = ProxyNetworkProvider(f"https://{PROXY}gateway.multiversx.com")
owner_on_network = provider.get_account(owner)
# ---------------------------------------------------------------- #
diff --git a/ESDTSender.py b/ESDTSender.py
index de5338f..dc5c1ee 100644
--- a/ESDTSender.py
+++ b/ESDTSender.py
@@ -6,6 +6,8 @@
from pathlib import Path
import argparse
+import requests
+import sys
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
@@ -44,16 +46,33 @@
# ---------------------------------------------------------------- #
# CONSTANTS
# ---------------------------------------------------------------- #
+
+config_network = {
+ "mainnet": {"chainID": "1", "proxy": ""},
+ "devnet": {"chainID": "D", "proxy": "devnet-"},
+ "testnet": {"chainID": "T", "proxy": "testnet-"}
+}
+
+CHAIN = "mainnet"
+CHAIN_ID = config_network[CHAIN]["chainID"]
+PROXY = config_network[CHAIN]["proxy"]
+
TOKEN_DECIMALS = args.decimals # default : 18
TOKEN_ID = args.id
+try:
+ response = requests.get(f'https://{PROXY}api.multiversx.com/tokens?identifier={TOKEN_ID}')
+ response.raise_for_status()
+except requests.exceptions.HTTPError as e:
+ print("ERROR: Token does not exist")
+ sys.exit()
# ---------------------------------------------------------------- #
# MAIN ESDT FUNCTION
# ---------------------------------------------------------------- #
def sendESDT(owner, owner_on_network, receiver, amount, signer):
payment = TokenPayment.fungible_from_amount(TOKEN_ID, amount, TOKEN_DECIMALS)
- config = DefaultTransactionBuildersConfiguration(chain_id="1")
+ config = DefaultTransactionBuildersConfiguration(chain_id=CHAIN_ID)
builder = ESDTTransferBuilder(
config=config,
@@ -80,7 +99,7 @@ def sendESDT(owner, owner_on_network, receiver, amount, signer):
pubkey = bytes.fromhex(pem.public_key.hex())
owner = Address(pubkey, "erd")
-provider = ProxyNetworkProvider("https://gateway.multiversx.com")
+provider = ProxyNetworkProvider(f"https://{PROXY}gateway.multiversx.com")
owner_on_network = provider.get_account(owner)
# ---------------------------------------------------------------- #
diff --git a/README.md b/README.md
index 634ad9b..cc74bbc 100644
--- a/README.md
+++ b/README.md
@@ -19,15 +19,12 @@ All libraries versions are in the requirements file, and they can be installed w
You need also need a [walletKey.pem](https://docs.multiversx.com/sdk-and-tools/sdk-py/deriving-the-wallet-pem-file/#__docusaurus/)
-## Devnet
+## Devnet & Tesnet
In order to use the Devnet you need to:
Change this line:
-```provider = ProxyNetworkProvider("https://gateway.multiversx.com")```
-and use this gateway: ```https://devnet-gateway.multiversx.com```
-
-Change this line: ```config = DefaultTransactionBuildersConfiguration(chain_id="1")```
-use ```chain_id="D"```
+```CHAIN = "mainnet"```
+and use this gateway: ```"devnet"``` or ```"testnet"```
## CLI
diff --git a/multipleESDTSender.py b/multipleESDTSender.py
index 3292020..d5f18bb 100644
--- a/multipleESDTSender.py
+++ b/multipleESDTSender.py
@@ -8,6 +8,8 @@
import json
import argparse
+import requests
+import sys
import pandas as pd
@@ -50,9 +52,27 @@
# ---------------------------------------------------------------- #
# CONSTANTS
# ---------------------------------------------------------------- #
+
+config_network = {
+ "mainnet": {"chainID": "1", "proxy": ""},
+ "devnet": {"chainID": "D", "proxy": "devnet-"},
+ "testnet": {"chainID": "T", "proxy": "testnet-"}
+}
+
+CHAIN = "mainnet"
+CHAIN_ID = config_network[CHAIN]["chainID"]
+PROXY = config_network[CHAIN]["proxy"]
+
TOKEN_DECIMALS = []
TOKEN_IDs = []
for index, id in enumerate(args.ids):
+ try:
+ response = requests.get(f'https://{PROXY}api.multiversx.com/tokens?identifier={id}')
+ response.raise_for_status()
+ except requests.exceptions.HTTPError as e:
+ print(f"ERROR: Token {id} does not exist")
+ sys.exit()
+
if index < len(args.decimals):
TOKEN_DECIMALS.append(args.decimals[index])
else:
@@ -69,7 +89,7 @@ def sendMultipleESDT(owner, owner_on_network, receiver, amounts, signer):
payment = TokenPayment.fungible_from_amount(TOKEN_IDs[index], amount_to_send, TOKEN_DECIMALS[index])
payments.append(payment)
- config = DefaultTransactionBuildersConfiguration(chain_id="1")
+ config = DefaultTransactionBuildersConfiguration(chain_id=CHAIN_ID)
builder = MultiESDTNFTTransferBuilder(
config=config,
@@ -96,7 +116,7 @@ def sendMultipleESDT(owner, owner_on_network, receiver, amounts, signer):
pubkey = bytes.fromhex(pem.public_key.hex())
owner = Address(pubkey, "erd")
-provider = ProxyNetworkProvider("https://gateway.multiversx.com")
+provider = ProxyNetworkProvider(f"https://{PROXY}gateway.multiversx.com")
owner_on_network = provider.get_account(owner)
# ---------------------------------------------------------------- #
diff --git a/requirements.txt b/requirements.txt
index 4ea4ebc..5a8d257 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,4 +1,4 @@
pandas==1.4.1
-multiversx-sdk-core===0.3.3
-multiversx-sdk-wallet===0.4.2
-multiversx-sdk-network-providers===0.6.7
+multiversx-sdk-core===0.4.1
+multiversx-sdk-wallet===0.6.2
+multiversx-sdk-network-providers===0.6.9
\ No newline at end of file