def get_last_block_nonce(args): proxy_url = args.proxy shard_id = args.shard_id proxy = ElrondProxy(proxy_url) nonce = proxy.get_last_block_nonce(shard_id) print(nonce) return nonce
def get_account_balance(args): proxy_url = args.proxy address = args.address proxy = ElrondProxy(proxy_url) balance = proxy.get_account_balance(Address(address)) print(balance) return balance
def get_account_transactions(args): proxy_url = args.proxy address = args.address proxy = ElrondProxy(proxy_url) account = proxy.get_account_transactions(Address(address)) print(account) return account
def get_contract_address_by_deploy_tx_hash(args: Any): args = utils.as_object(args) omit_fields = cli_shared.parse_omit_fields_arg(args) proxy = ElrondProxy(args.proxy) transaction = proxy.get_transaction(args.create_tx_hash, with_results=True) utils.omit_fields(transaction, omit_fields) _get_sc_address_from_tx(transaction)
def main(): pem_file_name = "walletKey.pem" pem_path = "~/Elrond/testnet/filegen/output" pem_file = path.join(pem_path, pem_file_name) parser = ArgumentParser() parser.add_argument("--proxy", default="http://localhost:7950") args = parser.parse_args() shard0_index = get_index_by_shard_id(pem_file, 0) shard1_index = get_index_by_shard_id(pem_file, 1) logging.basicConfig(level=logging.DEBUG) proxy = ElrondProxy(args.proxy) network = proxy.get_network_config() alice = Account(pem_file=pem_file, pem_index=shard0_index) bob = Account(pem_file=pem_file, pem_index=shard1_index) bob.sync_nonce(proxy) innerTx = Transaction() innerTx.nonce = bob.nonce innerTx.value = "0" innerTx.sender = bob.address.bech32() innerTx.receiver = "erd1qqqqqqqqqqqqqpgqrchxzx5uu8sv3ceg8nx8cxc0gesezure5awqn46gtd" # shard 2 address innerTx.gasPrice = 1000000000 innerTx.gasLimit = 500000000 innerTx.chainID = network.chain_id innerTx.version = network.min_tx_version innerTx.data = "version" innerTx.sign(bob) alice.sync_nonce(proxy) wrapperTx = Transaction() wrapperTx.nonce = alice.nonce wrapperTx.value = "0" wrapperTx.sender = alice.address.bech32() wrapperTx.receiver = bob.address.bech32() wrapperTx.gasPrice = 1000000000 wrapperTx.gasLimit = 501109000 wrapperTx.chainID = network.chain_id wrapperTx.version = network.min_tx_version wrapperTx.wrap_inner(innerTx) wrapperTx.sign(alice) wrapperTx.send(proxy)
def main(): parser = ArgumentParser() parser.add_argument("--proxy", required=True) parser.add_argument("--minter", required=True) parser.add_argument("--minted-value", required=False, type=int, default=MINTED_VALUE) parser.add_argument("--minted-folder", required=True) parser.add_argument("--minted-count", required=False, type=int) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) proxy = ElrondProxy(args.proxy) bunch = BunchOfTransactions() minter = Account(pem_file=args.minter) minted_repository = AccountsRepository(args.minted_folder) if args.minted_count: minted_repository.generate_accounts(args.minted_count) minter.sync_nonce(proxy) nonce = minter.nonce value = args.minted_value for minted in minted_repository.get_all(): bunch.add(minter, minted.address.bech32(), nonce, value, "", GAS_PRICE, GAS_LIMIT) nonce += 1 bunch.send(proxy)
def deploy_then_add_flow(): global contract # For deploy, we initialize the smart contract with the compiled bytecode contract = SmartContract(bytecode=bytecode) user.sync_nonce(ElrondProxy(args.proxy)) tx, address = environment.deploy_contract( contract=contract, owner=user, arguments=["0x0064"], gas_price=config.DEFAULT_GAS_PRICE, gas_limit=50000000, value=None, chain=config.get_chain_id(), version=config.get_tx_version()) logger.info("Tx hash: %s", tx) logger.info("Contract address: %s", address.bech32()) # We increment our copy of the nonce user.nonce += 1 environment.execute_contract(contract=contract, caller=user, function="add", arguments=["0x0064"], gas_price=config.DEFAULT_GAS_PRICE, gas_limit=50000000, value=None, chain=config.get_chain_id(), version=config.get_tx_version())
def parse_blocks(args: Any): gateway = ElrondProxy(constants.GATEWAY_URL) outfile = args.outfile nonces = args.blocks blocks = [] for nonce in nonces: try: hyperblock = gateway.get_hyperblock(nonce) post_process_hyperblock(hyperblock) except errors.ProxyRequestError: hyperblock = {"nonce": nonce} blocks.append(hyperblock) utils.dump_out_json(blocks, outfile)
def prepare_and_send_transaction(args): proxy = ElrondProxy(args.proxy) # Need to sync nonce owner = Account(pem_file=args.pem) owner.sync_nonce(proxy) args.nonce = owner.nonce prepared = do_prepare_transaction(args) tx_hash = prepared.send(proxy) print(tx_hash) return tx_hash
def tx1(): tx1 = Transaction() tx1.nonce = getNonce() tx1.value = sendAmount1 tx1.sender = sender tx1.receiver = wallet1 tx1.gasPrice = 1000000000 tx1.gasLimit = 50000 tx1.data = "" tx1.chainID = "D" # Currently set to the Devnet Chain tx1.version = 1 tx1.sign(account) proxy1 = ElrondProxy("https://devnet-api.elrond.com") tx1.send(proxy1) print("Sent " + sendAmount1 + " to " + wallet1)
def main(): parser = ArgumentParser() parser.add_argument("--proxy", default="https://testnet-gateway.elrond.com") parser.add_argument("--pem", required=True) parser.add_argument( "--batch-size", type=int, default=50, help="how many transactions to send before recalling nonce") parser.add_argument( "--sleep-before-recall", type=int, default=15, help="how many seconds to sleep before recalling nonce") parser.add_argument( "--sleep-after-tx", required=True, help="how many seconds to sleep after sending a transaction") args = parser.parse_args() logging.basicConfig(level=logging.WARNING) print("Press CTRL+C to stop the script execution") proxy = ElrondProxy(args.proxy) sender = Account(pem_file=args.pem) batch_size = int(args.batch_size) sleep_after_tx = int(args.sleep_after_tx) sleep_before_recall = int(args.sleep_before_recall) while True: print( f"Sleeping {sleep_before_recall} seconds before recalling nonce and sending {batch_size} transactions..." ) time.sleep(sleep_before_recall) try: sender.sync_nonce(proxy) print(f"Sender nonce recalled: nonce={sender.nonce}.") send_txs(proxy, sender, batch_size, sleep_after_tx) except errors.ProxyRequestError as err: logger.error(err)
def main(): parser = ArgumentParser() parser.add_argument("--proxy", required=True) parser.add_argument("--pem-folder", required=True) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) proxy = ElrondProxy(args.proxy) accounts_repository = AccountsRepository(args.pem_folder) bob = accounts_repository.get_account("bob") bob.sync_nonce(proxy) bunch = BunchOfTransactions() bunch.add( bob, "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz", bob.nonce, 10, "", 100000000000000, 50000) bunch.add( bob, "erd1l453hd0gt5gzdp7czpuall8ggt2dcv5zwmfdf3sd3lguxseux2fsmsgldz", bob.nonce + 1, 10, "", 100000000000000, 50000) bunch.send(proxy)
def main(): logging.basicConfig(level=logging.WARNING) parser = ArgumentParser() parser.add_argument("--proxy", default="http://myproxy:8079") parser.add_argument("--pem", required=True) args = parser.parse_args() items = payload.splitlines() items = [item.strip() for item in items if item] items = [parse_item(item) for item in items] print(len(items)) proxy = ElrondProxy(args.proxy) sender = Account(pem_file=args.pem) sender.sync_nonce(proxy) bunch = BunchOfTransactions() chain_id = "1" tx_version = 1 data = "foobar" gas_limit = 50000 + len(data) * 1500 cost = 0 for address, value in items: print(address, value) bunch.add(sender, address.bech32(), sender.nonce, str(value), data, GAS_PRICE, gas_limit, chain_id, tx_version) sender.nonce += 1 cost += value cost += gas_limit * GAS_PRICE print("Cost", cost) num_txs, _ = bunch.send(proxy) print("Sent", num_txs)
def main(): parser = ArgumentParser() parser.add_argument("--proxy", default="https://api.elrond.com") parser.add_argument("--pem", required=True) args = parser.parse_args() logging.basicConfig(level=logging.WARNING) print("Press CTRL+C to stop the script execution") proxy = ElrondProxy(args.proxy) sender = Account(pem_file=args.pem) while True: sleep_time = 15 print(f"Sleeping {sleep_time} seconds...") time.sleep(sleep_time) try: sender.sync_nonce(proxy) print(f"Sender nonce recalled: nonce={sender.nonce}.") send_txs(proxy, sender, 100) except errors.ProxyRequestError as err: logger.error(err)
def main(): parser = ArgumentParser() parser.add_argument("--proxy", required=True) parser.add_argument("--senders-folder", required=True) args = parser.parse_args() logging.basicConfig(level=logging.DEBUG) proxy = ElrondProxy(args.proxy) bunch = BunchOfTransactions() senders_repository = AccountsRepository(args.senders_folder) for sender in senders_repository.get_all(): sender.sync_nonce(proxy) # Send bad transactions to self nonce = sender.nonce + 42 for i in range(100): bunch.add(sender, sender.address.bech32(), nonce, 0, "", GAS_PRICE, GAS_LIMIT) nonce += 1 bunch.send(proxy)
def send_prepared_transaction(args): proxy = ElrondProxy(args.proxy) prepared = PreparedTransaction.from_file(args.tx) tx_hash = prepared.send(proxy) print(tx_hash) return tx_hash
def get_meta_block(args): proxy = ElrondProxy(args.proxy) block = proxy.get_meta_block(args.nonce) print(block) return block
def get_meta_nonce(args): proxy = ElrondProxy(args.proxy) nonce = proxy.get_meta_nonce() print(nonce) return nonce
def get_chain_id(args): proxy_url = args.proxy proxy = ElrondProxy(proxy_url) chain_id = proxy.get_chain_id() print(chain_id) return chain_id
def get_gas_price(args): proxy_url = args.proxy proxy = ElrondProxy(proxy_url) price = proxy.get_gas_price() print(price) return price
def _get_proxy(self): return ElrondProxy(self.url)
def get_num_shards(args): proxy_url = args.proxy proxy = ElrondProxy(proxy_url) num_shards = proxy.get_num_shards() print(num_shards) return num_shards
def get_height(args: Any): gateway = ElrondProxy(constants.GATEWAY_URL) outfile = args.outfile height = gateway.get_last_block_nonce(constants.METASHARD_ID) utils.dump_out_json({"height": height}, outfile)
from erdpy.proxy import ElrondProxy logger = logging.getLogger("examples") if __name__ == '__main__': parser = ArgumentParser() parser.add_argument("--proxy", help="Proxy URL", default=config.get_proxy()) parser.add_argument("--contract", help="Existing contract address") parser.add_argument("--pem", help="PEM file", required=True) args = parser.parse_args() logging.basicConfig(level=logging.INFO) proxy = ElrondProxy(args.proxy) network = proxy.get_network_config() chain = network.chain_id gas_price = network.min_gas_price tx_version = network.min_tx_version environment = TestnetEnvironment(args.proxy) user = Account(pem_file=args.pem) project = ProjectRust(Path(__file__).parent.parent) bytecode = project.get_bytecode() # We initialize the smart contract with an actual address if IF was previously deployed, # so that we can start to interact with it ("query_flow") contract = SmartContract(address=args.contract)
import json MainMenu, AgencyInfo, ChangeAgency, Wallets, WalletConfiguration, WalletStatus, \ RedelegationPerion, SubscriptionsMenu, availableSpace, availableSpace_threshold, MEXCalc = range(11) import requests from erdpy.contracts import SmartContract from erdpy.accounts import Address from erdpy.proxy import ElrondProxy import emoji mainnet_proxy = ElrondProxy('https://gateway.elrond.com') TrustStaking_contract = SmartContract('erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzhllllsp9wvyl') default_agency = 'trust staking' db_token = 'mongodb+srv://dragos:[email protected]/telegramBot?retryWrites=true&w=majority' bot_token = '1654360962:AAFNJTAZxdplj1nrgsv9LnfmCntOMR-DdGg' main_menu_message = emoji.cat + '''Main menu\n''' trust_agencies_backup = [ { 'name': "trust staking", 'address': 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqqzhllllsp9wvyl', 'last_eligible': 0 }, { 'name': "trust staking swiss", 'address': 'erd1qqqqqqqqqqqqqqqpqqqqqqqqqqqqqqqqqqqqqqqqqqqqq08llllsrvplwg', 'last_eligible': 0 }, { 'name': "trust staking us",
class NFTservice: def __init__(self, proxy=BC_PROXY, pem_file=ADMIN_PEMFILE): self._proxy = ElrondProxy(proxy) self.chain_id = self._proxy.get_chain_id() self.environment = TestnetEnvironment(proxy) log("Initialisation de l'admin avec " + pem_file) self._sender = Account(pem_file=pem_file) def execute(self, data, _sender=None, value="0", receiver=NFT_CONTRACT, gasLimit=60000000): if _sender is None: _sender = self._sender _sender.sync_nonce(self._proxy) t = Transaction() t.nonce = _sender.nonce t.version = get_tx_version() t.data = data t.receiver = receiver t.chainID = self._proxy.get_chain_id() t.gasLimit = gasLimit t.value = value t.sender = self._sender.address.bech32() t.gasPrice = DEFAULT_GAS_PRICE t.sign(self._sender) log("Execution d'une transaction sur " + BC_EXPLORER + "/address/" + t.sender) rc = t.send_wait_result(self._proxy, 60000) for r in rc["smartContractResults"]: if "data" in r: r["result"] = list() for p in r["data"].split("@"): if len(p) > 0: r["result"].append(hex_to_str(int(p, 16))) return rc["smartContractResults"] def init_token(self): rc = self.execute( "issueNonFungible@" + toHex("FEMISToken", False) + "@" + toHex("FEMIS", False), self._sender, NFT_CREATE_COST) if len(rc) > 0 and len(rc[0]["result"]) > 1: token_id = rc[0]["result"][1] log("Création de " + token_id) rc = self.execute("setSpecialRole@" + toHex(token_id, False) + "@" + self._sender.address.hex() + "@" + toHex("ESDTNFTCreate", False)) return rc def post(self, title, content, occ=1): #voir https://docs.elrond.com/developers/nft-tokens/ #rc=self.execute("issueNonFungible@"+str_to_hex("FEMISToken",False)+"@"+str_to_hex("FEMIS",False),self._sender,"5000000000000000000") #rc=self.execute("setSpecialRole@"+toHex(token_id)+"@"+self._sender.address.hex()+"@"+toHex("ESDTRoleNFTCreate")) hash = 0 data = "ESDTNFTCreate@" + toHex(TOKEN_ID) + "@" + toHex( occ) + "@" + toHex(title) + "@" + toHex(0) + "@" + toHex( hash) + "@" + toHex(content) + "@" + toHex( "https://dcp.f80.fr") rc = self.execute(data, receiver=self._sender.address.bech32(), gasLimit=60000000 + len(content + title) * 1500) return rc
def __init__(self, proxy=BC_PROXY, pem_file=ADMIN_PEMFILE): self._proxy = ElrondProxy(proxy) self.chain_id = self._proxy.get_chain_id() self.environment = TestnetEnvironment(proxy) log("Initialisation de l'admin avec " + pem_file) self._sender = Account(pem_file=pem_file)