Skip to content

Commit

Permalink
Adding transfer_token function to aptos_token_client.py and adding do…
Browse files Browse the repository at this point in the history
…cumentation tags for the new your_first_nft tutorial.
  • Loading branch information
xbtmatt committed Aug 10, 2023
1 parent 262d264 commit f805839
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions ecosystem/python/sdk/aptos_sdk/aptos_token_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from .account_address import AccountAddress
from .async_client import RestClient
from .bcs import Deserializer, Serializer
from .transactions import EntryFunction, TransactionArgument, TransactionPayload
from .transactions import (EntryFunction, TransactionArgument,
TransactionPayload)
from .type_tag import StructTag, TypeTag


Expand Down Expand Up @@ -383,6 +384,7 @@ def create_collection_payload(

return TransactionPayload(payload)

# :!:>create_collection
async def create_collection(
self,
creator: Account,
Expand All @@ -401,7 +403,7 @@ async def create_collection(
tokens_freezable_by_creator: bool,
royalty_numerator: int,
royalty_denominator: int,
) -> str:
) -> str: # <:!:create_collection
payload = AptosTokenClient.create_collection_payload(
description,
max_supply,
Expand Down Expand Up @@ -458,6 +460,7 @@ def mint_token_payload(

return TransactionPayload(payload)

# :!:>mint_token
async def mint_token(
self,
creator: Account,
Expand All @@ -466,7 +469,7 @@ async def mint_token(
name: str,
uri: str,
properties: PropertyMap,
) -> str:
) -> str: # <:!:mint_token
payload = AptosTokenClient.mint_token_payload(
collection, description, name, uri, properties
)
Expand Down Expand Up @@ -515,6 +518,27 @@ async def mint_soul_bound_token(
)
return await self.client.submit_bcs_transaction(signed_transaction)

# :!:>transfer_token
async def transfer_token(
self, sender: Account, token: AccountAddress, to: AccountAddress
) -> str:
payload = EntryFunction.natural(
"0x1::object",
"transfer",
[TypeTag(StructTag.from_str("0x4::token::Token"))],
[
TransactionArgument(token, Serializer.struct),
TransactionArgument(to, Serializer.struct),
],
)

signed_transaction = await self.client.create_bcs_signed_transaction(
sender, TransactionPayload(payload)
)
return await self.client.submit_bcs_transaction(
signed_transaction
) # <:!:transfer_token

async def burn_token(self, creator: Account, token: AccountAddress) -> str:
payload = EntryFunction.natural(
"0x4::aptos_token",
Expand Down

0 comments on commit f805839

Please sign in to comment.