Invoking An Auth Contract with Transaction Invoker Authorization using Soroban Python SDK
Tags: soroban, sorobanathon, stellar, python
Published: 2023-03-24 13:40:18

In my [previous post](https://dev.to/darkvallen/deploying-a-wrapped-token-contract-using-soroban-python-sdk-1me2), I showed you how to deploy and invoke an auth contract with stellar account authorization using Soroban Python SDK. In this post, we'll use Soroban Python SDK to invoke an auth contract with transaction invoker authorization. I will use auth contract that already deployed in previous post, so i dont need to deploy it again.

#Preparation
First, create a Futurenet account, this account will be used to deploy the auth contract and invoke the contract using Soroban Python SDK. Create account at [Stellar Laboratory](https://laboratory.stellar.org/#account-creator?network=futurenet) and make sure to fund them. The account that i will be using :

```
Public Key	GATQFKA7BV7LYYE6UJ2LRL56W3BZRRSWTINA6TG2EM5CCDORFIERAKWV
Secret Key	SCHKLGAGY7QGWUKUFDGHEQMSCPFZNMLEHQE6Y6WPGYGHQIM23T3NJE3C
```

The files that we're gonna use : 
> [`soroban_auth_with_transaction_invoke.py`](https://github.com/StellarCN/py-stellar-base/blob/soroban/examples/soroban_auth_with_transaction_invoke.py) - The python script to invoke the auth contract with transaction invoker authorization.

##Invoking the Contract
To invoke the auth contract, open the `soroban_auth_with_transaction_invoke.py` file and adjust the following parameters:
```python
contract_id = "af0aadafacc6bcb73b6ec9aeee03350ca0c6a3430e099d4b5dd371c6e07cc214"
tx_submitter_kp = Keypair.from_secret(
    "SCHKLGAGY7QGWUKUFDGHEQMSCPFZNMLEHQE6Y6WPGYGHQIM23T3NJE3C"
)

```
>`tx_submitter_kp`: the secret key of the account you'll use to submit the transaction and invoke the function. 
>`contract_id`: the contract ID of the  auth contract you want to invoke. **Replace the value with the contract ID you received from deploying contract before.**

Save the `soroban_auth_with_transaction_invoke.py` file with your changes.

Before running the script, i want to explain this specific codes :

```python
func_name = "increment"
args = [Address(tx_submitter_kp.public_key), Uint32(10)]

invocation = AuthorizedInvocation(
    contract_id=contract_id,
    function_name=func_name,
    args=args,
    sub_invocations=[],
)

contract_auth = ContractAuth(
    address=None,
    nonce=None,
    root_invocation=invocation,
)

source = soroban_server.load_account(tx_submitter_kp.public_key)
tx = (
    TransactionBuilder(source, network_passphrase)
    .add_time_bounds(0, 0)
    .append_invoke_contract_function_op(
        contract_id=contract_id,
        function_name=func_name,
        parameters=args,
        auth=[contract_auth],
    )
    .build()
)
```
From the script above the function of the contract that we're going to invoke is `increment` function and It sets address and `nonce` to `None` in the `ContractAuth`. **This is for transaction invoker authorization, where the transaction sender is the authorizer.**

Now we will run the script using this command :
```
python soroban_auth_with_transaction_invoke.py
```
We will get result:
```
transaction result: <SCVal [type=1, u32=<Uint32 [uint32=10]>]>
```

##Closing
In this blog post, we have gone over the steps to Deploy and Invoke Auth Contract with Transaction Invoker Authorization using Soroban Python SDK. From the script you will get an insight how basic Transaction Invoker Authorization implemented in Soroban Python SDK.