Send NFTs
After you have minted an
NFT,
you can easily send it by calling the Account.send_nft(addresses_nft_ids, options)
function.
As with any output, you can set a storage deposit and output unlock conditions. Keep in mind that if you set unlock conditions, whoever you send the native tokens to may need to claim them.
Code Example
Before you run the code example, make sure to update the token ID with one which is available in your account. If you haven't done so already, you can follow the how to mint a native token guide. If you don't know the token ID you can check your accounts balance to retrieve the available native tokens in your account.
The following example will:
- Create an account manager.
- Get Alice's account which was created in the first guide.
- Define the type of native token and amount to send.
- Send the native tokens calling the
Account.send_nft(addresses_nft_ids, options)
function.
- Rust
- Nodejs
- Python
- Java
This example uses dotenv, which is not safe for use in production environments.
loading...
Run the example by running the following command:
cargo run --example send_nft --release
loading...
You can run the example by running the following command from the wallet/bindings/nodejs/examples/
folder:
node 26-send-nft.js
loading...
You can run the example by running the following command from the binding/python/examples
folder:
python3 6-send-nft.py
loading...
Expected Output
- Rust
- Nodejs
- Python
- Java
Transaction: 0x4d3e01a0cf6d25e80af5ed774f0f741a476709a5517c21555e2c0351dda81f77
Block sent: http://localhost:14265/api/core/v2/blocks/0x7ad6ce0789ea5b5340b7045a13947af95737b3728410cdde8362021ac57f3731
{
payload: {
type: 6,
essence: {
type: 1,
networkId: '1856588631910923207',
inputs: [Array],
inputsCommitment: '0xd549b56a017e51a4ff053171b55aba62aac59e38a167067769991ccfb663ce1b',
outputs: [Array]
},
unlocks: [ [Object] ]
},
blockId: '0x40c74e3e9bc8913e3d5c75723d8e018695f3be8a78bd05479500eff4a7a10915',
inclusionState: 'Pending',
timestamp: '1663000240615',
transactionId: '0x03d4fe1335d0880db4163e7cb19735e016c803b015c9e65123e07de579ed41d2',
networkId: '1856588631910923207',
incoming: false,
note: null
}
Check your block on http://localhost:14265/api/core/v2/blocks/0x40c74e3e9bc8913e3d5c75723d8e018695f3be8a78bd05479500eff4a7a10915
Synced:{
'baseCoin':{
'total':'3302172702',
'available':'3302172702'
},
'requiredStorageDeposit':'910202100',
'nativeTokens':[
{
'tokenId':'0x08a5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d0100000000',
'total':'0x3de',
'available':'0x3de'
},
{
'tokenId':'0x08b83d49922e341d2cb45159707cfafdc9dc8fdb9d119543480dbaa5773eed8c4a0100000000',
'total':'0x64',
'available':'0x64'
}
],
'nfts':[
'0x77133189021f50d8d66e0678e553af9f46a832a24239653d3555edb8dc859e1f',
'0x1e808b7c6e603aaeb5f718881a74fedae72981ac7d5f0294eb561cad0e653566',
'0x1b670afba8d59a445cbaf167f1fda05879362e3ea034f5c4a0979fbeb5a3964b',
'0x3f0e11e9d9f48a57d0fba43d7d1158ee673cb8055f80a5ce45ad174c962c0d8a',
'0xdc8be91d779aac048aa9001ab99ecf12cf62a4701185a95f6206a1a201bfbe7c',
'0xceae643ff7c112a3adce8f55f7953ba0707ade21256a7a09068c0b47f7c62c5b',
'0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc'
],
'aliases':[
'0x96717e6d19c13b1c5b120d60b23217f541b5b779e51212e01d72e7fa1f7090cf',
'0xa5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d',
'0x97eb7a447cd62e1c373ff8188ba422f5c1b0687707d38e10e8366a1c20d33fea',
'0xf9c702ffe50c35d331b2df02295c2cc6d92f883530ff231bd76d1f6a72cb1d95'
],
'foundries':[
'0x08a5526c4a15558b709340822edf00cb348d8606a27e2e59b00432a0afe8afb74d0100000000'
],
'potentiallyLockedOutputs':{
'0x9a5869b61b29f17326e04b6161d9cd169687e79476c556bd0c3cbbc3648d4ff60000':False,
'0x850c1e43dff1a28a42d71edc6d4ad0b9f251c03993f9b0684a34f645514ffe270000':False
}
}
Sent transaction:{
'payload':{
'type':6,
'essence':{
'type':1,
'networkId':'1856588631910923207',
'inputs':[
{
'type':0,
'transactionId':'0x84debb878f8e124f2bd893e04c6672a8ad31788c47a520f77c11bdb03727ef1c',
'transactionOutputIndex':3
}
],
'inputsCommitment':'0xb70cc0104197c9b9b1bc7199b9093e47d710b0e7e14b7bc09a79ebc7e42e16a1',
'outputs':[
{
'type':6,
'amount':'47500',
'nftId':'0x17f97185f80fa56eab974de6b7bbb80fa812d4e8e37090d166a0a41da129cebc',
'unlockConditions':[
{
'type':0,
'address':{
'type':0,
'pubKeyHash':'0x60200bad8137a704216e84f8f9acfe65b972d9f4155becb4815282b03cef99fe'
}
}
],
'features':[
{
'type':2,
'data':'0x68656c6c6f'
}
],
'immutableFeatures':[
{
'type':2,
'data':'0x68656c6c6f'
}
]
}
]
},
'unlocks':[
{
'type':0,
'signature':{
'type':0,
'publicKey':'0xe62838fda7e8b77bf80e49967f0f089ae2a7230547d5231649732952f6336fae',
'signature':'0x079dfe7ab4830be937757d3362ef5dab8d0d70297ab4dce8a3ab79f2a8b28610ff8d84fe037e642afa28c07a3f87ed2072930f57e9b7f8390e9e117e26966809'
}
}
]
},
'blockId':'0x5c49a0c8b9ee920ca575d895842c43ace5bfd2feb2ccc611eb37ec4cde7acabc',
'inclusionState':'Pending',
'timestamp':'1665918220888',
'transactionId':'0x3158626d7f404bded6af815f104e4001009a3f82fab7f9eb267cc691d039eed5',
'networkId':'1856588631910923207',
'incoming':False,
'note':None
}
{
"payload": {
"type": 6,
"essence": {
"type": 1,
"networkId": "1856588631910923207",
"inputs": [
{
"type": 0,
"transactionId": "0xd96c9cdf8c6b095f7ab44105f8298c766a7433664db651bfbd7832566d59f103",
"transactionOutputIndex": 0
}
],
"inputsCommitment": "0xd64acb6fec68315c200484458fb0a2c1e9b7d06106aecdcb9c86403d955ad69a",
"outputs": [
{
"type": 6,
"amount": "52000",
"nftId": "0xdbed22679570aecc16da90648836607981e87c1ed3e3a24daf0942aa29a66003",
"unlockConditions": [
{
"type": 0,
"address": {
"type": 0,
"pubKeyHash": "0x4cfde0600797ae07d19d67d78910e70950bfdaf716f0035e9a30b97828aaf6a2"
}
}
],
"features": [
{
"type": 2,
"data": "0x5368696d6d65722e20546f6b656e697a652045766572797468696e672e2048656c6c6f2066726f6d20746865204a6176612062696e64696e672e"
}
]
}
]
},
"unlocks": [
{
"type": 0,
"signature": {
"type": 0,
"publicKey": "0xde3152ce9d67415b9c5a042ea01caccc3f73ff1c0c77036874cb8badf9798d56",
"signature": "0xc42fd26b652581e6b2f58ef316b9817830093ae959d716f06c97284fadad72e39838031205d89afa3f0177ae2b1780435945be6a29274a1c66ad47d622cf630b"
}
}
]
},
"blockId": "0xa2dc2b45e42ef4c5f847f329faa27ee7b3e50ede0d6b46aeed996f4d74e87b95",
"inclusionState": "Pending",
"timestamp": "1664876443672",
"transactionId": "0xb423ef2155828a4b301795a77357c70bdac76c47f6ee1a20af6a298540fd9b86",
"networkId": "1856588631910923207",
"incoming": false
}