Transferring Tokens to Users
Transferring tokens is a fundamental operation in managing Non-Fungible Tokens (NFTs). The tokenTransfer
method provided by the edeXa ERC721 SDK simplifies this process, enabling secure and straightforward token transfers between users. This guide outlines how to use this method to transfer tokens.
Overview of the tokenTransfer
Method
The tokenTransfer
method facilitates the transfer of ownership of a specific token from one user to another. It's an essential feature for applications that involve trading, gifting, or selling NFTs.
Prerequisites
- Installation of the edeXa ERC721 SDK in your project.
- An authentication token obtained through the SDK's authentication method. This token is necessary to authorize your requests.
Sample Code Snippet
Here is a JavaScript code snippet demonstrating the use of the tokenTransfer
method:
import { ERC721, Network } from 'edeXa-sdk';
async function tokenTransfer() {
const settings = {
network: Network.SANDBOX, // Or Network.MAINNET for production environments
authorization: `Bearer ${token}`, // Replace `${token}` with your actual authentication token
};
const erc721 = new ERC721(settings);
const dataToTokenTransfer = {
to: 'Enter the username of the user to whom you want to transfer the tokens', // Required
tokenId: 'Enter the tokenId to transfer', // Required
chaincode: 'Optional smart contract name', // Managing tokens' smart contract
channel: 'Optional blockchain channel name', // Blockchain channel
};
try {
const tokenTransferResponse = await erc721.tokenTransfer(
dataToTokenTransfer
);
// Handle success
} catch (error) {
// Handle error
}
}
Request Parameters
Parameter | Required | Type | Description |
---|---|---|---|
to | Yes | String | The username of the user to whom the tokens are being transferred. |
tokenId | Yes | String | The unique identifier of the token to transfer. |
chaincode | No | String | Name of the smart contract managing the tokens (optional). |
channel | No | String | Name of the blockchain channel (optional). |
Response Format
Upon successful execution, the tokenTransfer
method returns a response containing details about the transfer operation.
Attribute | Type | Description |
---|---|---|
from | String | The username of the user who initiated the transfer. |
to | String | The username of the user who received the token. |
tokenId | Number | The unique identifier of the token that was transferred. |