Skip to main content

Python client for RallyProtocol

Project description

PyRally

Welcome to the Rally Protocol Python SDK! This SDK provides an easy way to interact with the Rally Protocol gas station network. With this SDK, you can easily submit gasless transactions to the Rally GSN API. For more information about gasless transactions and the Rally Protocol, visit Rally Protocol

Installation

pip install py-rally-sdk

Usage

Navigate to Rally App to generate API Keys for polygon mumbai and polygon pos.

Getting started with the RallyNetworkClient

The network client allows you to send transactions to the relayer and also transfer supported tokens from one address to another. The SDK provides both mumbai and polygon POS network clients.

from py_rally import NetworkClientBuilder
from py_rally.custom_types import Account, MetaTxMethod

# Create an Account Object
account = Account('<PRIVATE_KEY>', '<ADDRESS>')

# Get polygon mumbai testnet client
mumbai_network_client = NetworkClientBuilder.get_rally_mumbai_client()
mumbai_network_client.set_api_key('<RALLY MUMBAI API KEY>')

# Get polygon mainnet client
polygon_network_client = NetworkClientBuilder.get_rally_polygon_client()
polygon_network_client.set_api_key('<RALLY MAINNET API KEY>')

# Claim Rally into account on testnet
mumbai_network_client.claim_rally(account)

# Transfer rally to another account on testnet
mumbai_network_client.token_transfer(
   account,
   '<TO ADDRESS>',
   1,
   '<RALLY TESTNET TOKEN ADDRESS>',
   MetaTxMethod.ExecuteMetaTransaction
) # Rally Token supports execute meta transaction.

Calling contracts not supported by the SDK

The SDK allows sending transactions to the relayer API for contracts not supported by the SDK. The contract has to be a supported contract on Rally Protocol. Rally Protocol supports ERC2771 compatible contracts. For more information about this, visit Rally documentation

from py_rally import NetworkClientBuilder
from py_rally.custom_types import Account

client = NetworkClientBuilder.get_rally_polygon_client()
client.set_api_key('<API KEY>')

# Build raw transaction using web3.py
signer = Account('<PRIVATE_KEY>', '<ADDRESS>')
ABI = ['CONTRACT ABI']
contract_address = client.web3.to_checksum_address('<Address>')
contract = client.web3.eth.contract(contract_address, abi=ABI)
tx = contract.functions.claim().build_transaction({'from': signer.address})
gsn_txn = {
    'from_address': tx['from'],
    'to': tx['to'],
    'data': tx['data'],
    'max_fee_per_gas': hex(tx['maxFeePerGas']),
    'max_priority_fee_per_gas': hex(tx['maxPriorityFeePerGas']),
    'gas': hex(tx['gas']),
    'value': tx['value'],
    'paymaster_data': '0x',
    'client_id': 1,
}
tx_hash = client.relay_transaction(signer, gsn_txn)

Built with ❤️ by teepy🇳🇬

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_rally_sdk-1.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_rally_sdk-1.1.1-py3-none-any.whl (19.1 kB view details)

Uploaded Python 3

File details

Details for the file py_rally_sdk-1.1.1.tar.gz.

File metadata

  • Download URL: py_rally_sdk-1.1.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for py_rally_sdk-1.1.1.tar.gz
Algorithm Hash digest
SHA256 28c766c3e9a2923a5cf6943f4625a6aba1c7e4f4c3942739eb32ad09894046f8
MD5 df7a91190bb7793edbaba6c182120be8
BLAKE2b-256 503234882cdae36f3e8f7a20a7ef72ca1d3557c07e590d5d942dae2ec7853dd7

See more details on using hashes here.

File details

Details for the file py_rally_sdk-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: py_rally_sdk-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for py_rally_sdk-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b21df508729e0e263d15541b4e1d340f0cbe580e8e3e4a8594231bf5b2f76870
MD5 d6035d49f873c5b8b6496e5e5102d582
BLAKE2b-256 c8f1fff81948866c58ba59b3430d50e8fbe5c5c7b3fa8e91ebb14b09bfafcf8a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page