#Call contract function requiring auth from python sdk

8 messages · Page 1 of 1 (latest)

ornate minnow
#

Hi. Im trying to call debug contract having auth required. Initially i've tried to call incr_allow for token contract but then during debug came to simple function which accepts account address as argument returns it back

    fn test_sign(_env: Env, address: Address) -> BytesN<32> {
        address.require_auth();
        address.account_id().unwrap()
    }

then i try to call it via python sdk in the same way as examples mention

    nonce = soroban_server.get_nonce(debug_contract_id, distributor_keypair.public_key)
    contract_auth = ContractAuth(
        address=Address(distributor_keypair.public_key),
        nonce=nonce,
        root_invocation=AuthorizedInvocation(
            contract_id=debug_contract_id,
            function_name='test_sign',
            args=[Address(distributor_keypair.public_key)],
            sub_invocations=[],
        ),
    )
    contract_auth.sign(distributor_keypair, network_passphrase)

    tx = (
        TransactionBuilder(distributor_account, network_passphrase)
        .set_timeout(300)
        .append_invoke_contract_function_op(
            contract_id=debug_contract_id,
            function_name="test_sign",
            parameters=[Address(distributor_keypair.public_key)],
            auth=[contract_auth],
        )
        .build()
    )
    tx_result = submit_transaction(soroban_server, tx, distributor_keypair)
    if not tx_result:
        raise RuntimeError
    transaction_meta = xdr.TransactionMeta.from_xdr(tx_result.result_meta_xdr)
    result = transaction_meta.v3.tx_result.result.results[0].tr.invoke_host_function_result.success  # type: ignore
    print(f"{bcolors.OKGREEN}result: {result.bytes.sc_bytes.hex()}{bcolors.ENDC}")

if i comment require_auth function in my contract it works well. but with auth required it gives me invokeHostFunctionResult: [invokeHostFunctionTrapped]

contract id: 7b0663d0d49ca605eb511c88914c627d271b0abc8cb47eb065efc7069b80ada6

tall phoenix
#

Hello, I am getting the same problem with auth using python SDK.
Anyone could help with it?

tranquil nacelle
#

@arctic knot Any chance you can spot what's up with the above?

arctic knot
#

Also, please use the code from the soroban branch.