Skip to content

Commit

Permalink
Merge pull request #7 from PABourdais/verify-token
Browse files Browse the repository at this point in the history
Verify token before sending
  • Loading branch information
PABourdais authored Mar 31, 2023
2 parents 76879e5 + bbe236c commit 53c308d
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 15 deletions.
18 changes: 16 additions & 2 deletions EGLDSender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)

# ---------------------------------------------------------------- #
Expand Down
23 changes: 21 additions & 2 deletions ESDTSender.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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,
Expand All @@ -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)

# ---------------------------------------------------------------- #
Expand Down
9 changes: 3 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <br><br>
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

Expand Down
24 changes: 22 additions & 2 deletions multipleESDTSender.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import json
import argparse
import requests
import sys

import pandas as pd

Expand Down Expand Up @@ -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:
Expand All @@ -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,
Expand All @@ -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)

# ---------------------------------------------------------------- #
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 53c308d

Please sign in to comment.