Skip to content

Commit

Permalink
Adding the optional TypeTag parameter to the object transfer function…
Browse files Browse the repository at this point in the history
… and changed it to use `0x1::object::transfer` instead of `0x1::object::transfer_call`. Added the `0x4::aptos_token::AptosToken` TypeTag to the `transfer_object` call underlying the `transfer_token` call.
  • Loading branch information
xbtmatt committed Aug 6, 2023
1 parent 401b61f commit 3790625
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
7 changes: 6 additions & 1 deletion ecosystem/python/sdk/aptos_sdk/aptos_token_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,12 @@ async def mint_soul_bound_token(
async def transfer_token(
self, owner: Account, token: AccountAddress, to: AccountAddress
) -> str: # <:!:transfer_token
return await self.client.transfer_object(owner, token, to)
return await self.client.transfer_object(
owner,
token,
to,
TypeTag(StructTag.from_str("0x4::aptos_token::AptosToken")),
)

async def burn_token(self, creator: Account, token: AccountAddress) -> str:
payload = EntryFunction.natural(
Expand Down
13 changes: 9 additions & 4 deletions ecosystem/python/sdk/aptos_sdk/async_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
TransactionArgument,
TransactionPayload,
)
from .type_tag import StructTag, TypeTag

U64_MAX = 18446744073709551615

Expand Down Expand Up @@ -751,9 +752,13 @@ async def get_collection(
"0x3::token::CollectionData",
collection_name,
)

async def transfer_object(
self, owner: Account, object: AccountAddress, to: AccountAddress
self,
owner: Account,
object: AccountAddress,
to: AccountAddress,
type_tag: TypeTag = TypeTag(StructTag.from_str("0x1::object::ObjectCore")),
) -> str:
transaction_arguments = [
TransactionArgument(object, Serializer.struct),
Expand All @@ -762,8 +767,8 @@ async def transfer_object(

payload = EntryFunction.natural(
"0x1::object",
"transfer_call",
[],
"transfer",
[type_tag],
transaction_arguments,
)

Expand Down
4 changes: 2 additions & 2 deletions ecosystem/python/sdk/examples/aptos-token.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from aptos_sdk.account import Account
from aptos_sdk.account_address import AccountAddress
from aptos_sdk.aptos_token_client import AptosTokenClient, Property, PropertyMap, Object
from aptos_sdk.aptos_token_client import AptosTokenClient, Object, Property, PropertyMap
from aptos_sdk.async_client import FaucetClient, RestClient

from .common import FAUCET_URL, NODE_URL
Expand Down Expand Up @@ -113,7 +113,7 @@ async def main():
print(f"Token: {token_addr}\n")
print(f"Owner: {token_data.resources[Object].owner}")
print(" ...transferring... ")
txn_hash = await rest_client.transfer_object(alice, token_addr, bob.address())
txn_hash = await token_client.transfer_token(alice, token_addr, bob.address())
await rest_client.wait_for_transaction(txn_hash)
token_data = await token_client.read_object(token_addr)
print(f"Owner: {token_data.resources[Object].owner}\n")
Expand Down

0 comments on commit 3790625

Please sign in to comment.