Module

NFT (ERC-721) — 2–10 credits

Interact with ERC-721 non-fungible tokens: retrieve metadata and ownership info (2 credits), check owner balances (2 credits), and transfer tokens between addresses (10 credits).

API Key
info()
GET 2 credits API Key

Retrieve metadata, current owner, and token URI for a specific ERC-721 token.

Parameters

NameTypeRequiredDescription
$contractAddressstringYesERC-721 contract address
$tokenIdintYesToken ID (integer)
$network?stringNoNetwork name. Defaults to WEB3_DEFAULT_NETWORK

Example

$nft = Web3Api::nft()->info(
    contractAddress: '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
    tokenId:         42,
    network:         'polygon',
);

Response

[
  'contract'  => '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
  'token_id'  => 42,
  'owner'     => '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  'token_uri' => 'ipfs://QmXyz.../42.json',
  'metadata'  => [
    'name'        => 'Token #42',
    'description' => 'A unique digital collectible',
    'image'       => 'ipfs://QmXyz.../42.png',
    'attributes'  => [/* ... */],
  ],
]
balance()
GET 2 credits API Key

Get the total number of ERC-721 tokens held by an address for a given contract.

Parameters

NameTypeRequiredDescription
$contractAddressstringYesERC-721 contract address
$ownerAddressstringYesWallet address to check
$network?stringNoNetwork name. Defaults to WEB3_DEFAULT_NETWORK

Example

$result = Web3Api::nft()->balance(
    contractAddress: '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
    ownerAddress:    '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
    network:         'polygon',
);

echo $result['balance'];  // 3 — owns 3 tokens from this collection

Response

[
  'contract' => '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
  'owner'    => '0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045',
  'balance'  => 3,
]
transfer()
POST 10 credits API Key

Transfer an ERC-721 token from one address to another using safeTransferFrom. Requires the sender's private key.

Parameters

NameTypeRequiredDescription
$contractAddressstringYesERC-721 contract address
$fromAddressstringYesCurrent token owner's address
$privateKey?stringNoPrivate key of the current owner. Pass null to use the stored managed wallet
$toAddressstringYesRecipient address
$tokenIdintYesToken ID to transfer
$network?stringNoNetwork name. Defaults to WEB3_DEFAULT_NETWORK

Example

$tx = Web3Api::nft()->transfer(
    contractAddress: '0xBCE3781ae7Ca1a5e050Bd9C4c77369867eBc307e',
    fromAddress:     '0xCURRENT_OWNER',
    privateKey:      '0xOWNER_PRIVATE_KEY',
    toAddress:       '0xNEW_OWNER',
    tokenId:         42,
    network:         'polygon',
);

echo $tx['tx_hash'];  // "0xabcdef..."
echo $tx['status'];   // "pending"

Response

[
  'tx_hash' => '0xabcdef1234567890...',
  'status'  => 'pending',
]