Skip to content

Module: wallet

Class for interacting with an Infernet Wallet contract.

Attributes

  • address: The address of the wallet contract

Public Methods

  • approve(spender: ChecksumAddress, token: ChecksumAddress, amount: int) -> TxReceipt: Approve a spender to spend a certain amount of tokens
  • owner() -> ChecksumAddress: Get the owner of the wallet
  • get_balance() -> int: Get the native balance of the wallet
  • get_token_balance(token: ChecksumAddress) -> int: Get the balance of a token in the wallet

InfernetWallet

Source code in src/infernet_client/chain/wallet.py
class InfernetWallet:
    def __init__(self, address: ChecksumAddress, rpc: RPC):
        """
        Args:
            address: The address of the wallet contract
            rpc: The RPC object to interact with the blockchain
        """
        self.address = address
        self._rpc = rpc
        self._contract = rpc.get_contract(address=address, abi=WALLET_ABI)

    async def approve(
        self, spender: ChecksumAddress, token: ChecksumAddress, amount: int
    ) -> TxReceipt:
        """
        Approve a spender to spend a certain amount of tokens

        Args:
            spender: The address of the spender
            token: The address of the token to approve
            amount: The amount to approve

        Returns:
            The transaction receipt
        """
        tx_hash = await self._contract.functions.approve(
            spender, token, amount
        ).transact()
        receipt = await self._rpc.get_tx_receipt(tx_hash)
        assert await self._contract.functions.allowance(spender, token).call() == amount
        return receipt

    async def owner(self) -> ChecksumAddress:
        """
        Get the owner of the wallet

        Returns:
            The address of the owner
        """
        return Web3.to_checksum_address(await self._contract.functions.owner().call())

    async def get_balance(self) -> int:
        """
        Get the native balance of the wallet

        Returns:
            The native balance
        """
        return await self._rpc.get_balance(self.address)

    async def get_token_balance(self, token: ChecksumAddress) -> int:
        """
        Get the balance of a token in the wallet

        Args:
            token: The address of the token

        Returns:
            The balance of the token
        """
        return await Token(token, self._rpc).balance_of(self.address)

__init__(address, rpc)

Parameters:

Name Type Description Default
address ChecksumAddress

The address of the wallet contract

required
rpc RPC

The RPC object to interact with the blockchain

required
Source code in src/infernet_client/chain/wallet.py
def __init__(self, address: ChecksumAddress, rpc: RPC):
    """
    Args:
        address: The address of the wallet contract
        rpc: The RPC object to interact with the blockchain
    """
    self.address = address
    self._rpc = rpc
    self._contract = rpc.get_contract(address=address, abi=WALLET_ABI)

approve(spender, token, amount) async

Approve a spender to spend a certain amount of tokens

Parameters:

Name Type Description Default
spender ChecksumAddress

The address of the spender

required
token ChecksumAddress

The address of the token to approve

required
amount int

The amount to approve

required

Returns:

Type Description
TxReceipt

The transaction receipt

Source code in src/infernet_client/chain/wallet.py
async def approve(
    self, spender: ChecksumAddress, token: ChecksumAddress, amount: int
) -> TxReceipt:
    """
    Approve a spender to spend a certain amount of tokens

    Args:
        spender: The address of the spender
        token: The address of the token to approve
        amount: The amount to approve

    Returns:
        The transaction receipt
    """
    tx_hash = await self._contract.functions.approve(
        spender, token, amount
    ).transact()
    receipt = await self._rpc.get_tx_receipt(tx_hash)
    assert await self._contract.functions.allowance(spender, token).call() == amount
    return receipt

get_balance() async

Get the native balance of the wallet

Returns:

Type Description
int

The native balance

Source code in src/infernet_client/chain/wallet.py
async def get_balance(self) -> int:
    """
    Get the native balance of the wallet

    Returns:
        The native balance
    """
    return await self._rpc.get_balance(self.address)

get_token_balance(token) async

Get the balance of a token in the wallet

Parameters:

Name Type Description Default
token ChecksumAddress

The address of the token

required

Returns:

Type Description
int

The balance of the token

Source code in src/infernet_client/chain/wallet.py
async def get_token_balance(self, token: ChecksumAddress) -> int:
    """
    Get the balance of a token in the wallet

    Args:
        token: The address of the token

    Returns:
        The balance of the token
    """
    return await Token(token, self._rpc).balance_of(self.address)

owner() async

Get the owner of the wallet

Returns:

Type Description
ChecksumAddress

The address of the owner

Source code in src/infernet_client/chain/wallet.py
async def owner(self) -> ChecksumAddress:
    """
    Get the owner of the wallet

    Returns:
        The address of the owner
    """
    return Web3.to_checksum_address(await self._contract.functions.owner().call())