aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

[Bug] python sdk - transfers not working with api v1

Open EmilRejman opened this issue 3 years ago • 4 comments

🐛 Bug

With the entry of API v1 python sdk transfers (nor bcs or normal one) are not working.

To reproduce

Code snippet to reproduce

from aptos_sdk.client import RestClient
from aptos_sdk.account import Account
from aptos_sdk.account_address import AccountAddress
from aptos_sdk import ed25519

private_key_hex = "0x...."

# generate account from private_key
private_key = ed25519.PrivateKey.from_hex(private_key_hex)
account = Account(
    account_address=AccountAddress.from_key(private_key.public_key()),
    private_key=private_key,
)

client = RestClient(base_url="https://fullnode.devnet.aptoslabs.com/v1")

tx = client.transfer(sender=account, recipient=AccountAddress.from_hex("0x1946a3aa2fc5e74b920767bc28178be327c7ab1eea10de6b7b4f28a30688aa04"), amount=1)

tx = client.bcs_transfer(sender=account, recipient=AccountAddress.from_hex("0x1946a3aa2fc5e74b920767bc28178be327c7ab1eea10de6b7b4f28a30688aa04"), amount=1)

Stack trace/error message

assert res.status_code == 200, res.text
AssertionError: {"message":"parse request payload error: Expected input type \"TransactionPayload\", found {\"type\":\"script_function_payload\",\"function\":\"0x1::coin::transfer\",\"type_arguments\":[\"0x1::aptos_coin::AptosCoin\"],\"arguments\":[\"0x1946a3aa2fc5e74b920767bc28178be327c7ab1eea10de6b7b4f28a30688aa04\",\"1\"]}. (occurred while parsing \"UserTransactionRequestInner\") (occurred while parsing \"EncodeSubmissionRequest\")","error_code":"web_framework_error","vm_error_code":null}


with bcs:

assert response.status_code == 202, f"{response.text} - {signed_transaction}"
AssertionError: {"message":"Failed to deserialize input into SignedTransaction","error_code":"invalid_input","vm_error_code":null} - Transaction: RawTranasction:
    sender: 0xf28eeea75ee29436a2759fd204b1b064874f06b1543c01f8bdb2dbd0efa5fc5e
    sequence_number: 1
    payload: 0x0000000000000000000000000000000000000000000000000000000000000001::coin::transfer::<[0x0000000000000000000000000000000000000000000000000000000000000001::aptos_coin::AptosCoin]>([b"\x19F\xa3\xaa/\xc5\xe7K\x92\x07g\xbc(\x17\x8b\xe3'\xc7\xab\x1e\xea\x10\xdek{O(\xa3\x06\x88\xaa\x04", b'\x01\x00\x00\x00\x00\x00\x00\x00'])
    max_gas_amount: 2000
    gas_unit_price: 1
    expiration_timestamps_secs: 1662391579
    chain_id: 25

Expected Behavior

Up until v1 api these functions were working correctly

System information

Please complete the following information:

  • mac m1 os

Additional context

I assume it is related to change of script_function_payload to entry_function_payload. Also REST request parameters might have changed - but this was not addressed in python sdk.

EmilRejman avatar Sep 05 '22 15:09 EmilRejman

Could you let me know where you installed this SDK from and how? Was this from pypi?

banool avatar Sep 07 '22 22:09 banool

Yes, it was the newest version then, https://pypi.org/project/aptos-sdk/ v0.2.0.

After update to v0.2.0.1 it is still not working.

EmilRejman avatar Sep 08 '22 10:09 EmilRejman

Still not working with version v0.3.0

EmilRejman avatar Sep 12 '22 11:09 EmilRejman

I just ran the code from 0.3.0 that's in the current repository without issue. I cannot repro this :(. Can you please ensure you're actually running 0.3.0. What is the md5 of your client.py.

davidiw avatar Sep 13 '22 00:09 davidiw

Okay, there was an error while upgrading with --upgrade:

WARNING: Requested aptos-sdk==0.3.0 from https://files.pythonhosted.org/packages/06/48/5d3ee3f4b6fd2b7399139bb4721452e8e2e16c9225e33b88797921355e61/aptos_sdk-0.3.0.tar.gz, but installing version 0.2.0
Discarding https://files.pythonhosted.org/packages/06/48/5d3ee3f4b6fd2b7399139bb4721452e8e2e16c9225e33b88797921355e61/aptos_sdk-0.3.0.tar.gz (from https://pypi.org/simple/aptos-sdk/) (requires-python:>=3.7): Requested aptos-sdk==0.3.0 from https://files.pythonhosted.org/packages/06/48/5d3ee3f4b6fd2b7399139bb4721452e8e2e16c9225e33b88797921355e61/aptos_sdk-0.3.0.tar.gz has inconsistent version: filename has '0.3.0', but metadata has '0.2.0'

When 0.3.0 installed explicitly now everything is working :) Thx!

EmilRejman avatar Sep 19 '22 18:09 EmilRejman