This is the original code to send a single NFT using the send_nft()
method
from iota_wallet import IotaWallet
# In this example we will send an nft
wallet = IotaWallet('./alice-database')
account = wallet.get_account('Alice')
# Sync account with the node
response = account.sync()
print(f'Synced: {response}')
wallet.set_stronghold_password("some_hopefully_secure_password")
outputs = [{
"address": "rms1qpszqzadsym6wpppd6z037dvlejmjuke7s24hm95s9fg9vpua7vluaw60xu",
"nftId": "0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc",
}]
transaction = account.send_nft(outputs)
print(f'Sent transaction: {transaction}')
Source: https://github.com/iotaledger/wallet.rs/blob/develop/wallet/bindings/python/examples/6-send-nft.py
Although, to add an expiration output unlock condition, it works differently.
To add an expiration condition, which for this example and in laymen terms means that the NFT will be sent back to my wallet, if the recipient does not claim it manually, one has to build the output
manually.
Here are the examples that show how to prepare outputs using wallet.rs
What you will need is the expiration time in UnixTime format like e.g. 1681286520
To calculate that you can use a site like https://unixtime.org/ or from the GNU/Linux command line with date -d"12 April 2023 10:02 AM" +%s
and here is the code to prepare the output and send one specific NFTs given it's nftId with an expiration time:
from iota_wallet import IotaWallet
# In this example we will mint an nft
wallet = IotaWallet('./alice-database')
account = wallet.get_account('Alice')
# Sync account with the node
response = account.sync()
print(f'Synced: {response}')
wallet.set_stronghold_password("some_hopefully_secure_password")
# The amount is 0, because we are not sending tokens but the amount field has to have a value
output = account.prepare_output(
{
"amount": "0",
"recipientAddress": "rms1qzsvgp676a3xtru3sh9nmdd2qxzkmktxkgvhxcc2n20y50dq6nma72795cc",
"unlocks":
{
"expirationUnixTime": 1681286520,
},
"assets":
{
"nftId": "0x244df0071cb93037fa376921b5de2083b8aed1814c26d778f1674cfa47ea448c",
},
}
)
transaction = account.send_outputs([output])
print(f'Sent transaction: {transaction}')