Skip to content

Allow contract calls with amounts

It is common to call a contract entrypoint and send it some Tz [1]. However, currently, it looks like if a transaction is a contract call, then only the parameters are passed: https://yourlabs.io/oss/djtezos/-/blob/master/djtezos/tezos.py#L226

I would replace this line with something along the lines of:

 def send(self, transaction):
     logger.debug(f'{transaction}({transaction.args}): get_client')
     client = self.get_client(transaction.sender.private_key)
     logger.debug(f'{transaction}({transaction.args}): counter = {client.account()["counter"]}')
     ci = client.contract(transaction.contract_address)
     method = getattr(ci, transaction.function)
     try:
-       tx = method(*transaction.args)
+       tx = method(*transaction.args).with_amount(transaction.amount)
     except ValueError as e:
         raise PermanentError(*e.args)
     result = self.write_transaction(tx, transaction)
     logger.debug(f'{transaction}({transaction.args}): {result}')
     return result

[1] For instance, when adding liquidity to a decentralized exchange (AMM, uniswap like), for instance Tezos's Dexter: https://gitlab.com/dexter2tz/dexter2tz/-/blob/master/dexter.mligo#L230