Skip to main content
Glama

transfer_erc1155

Facilitates the transfer of ERC1155 tokens between addresses across Ethereum-compatible networks. Specify token details, recipient, and network to execute secure, multi-token transactions.

Instructions

Transfer ERC1155 tokens to another address. ERC1155 is a multi-token standard that can represent both fungible and non-fungible tokens in a single contract.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
amountYesThe quantity of tokens to send (e.g., '1' for a single NFT or '10' for 10 fungible tokens)
networkNoNetwork name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', 'polygon') or chain ID. ERC1155 tokens exist across many networks. Defaults to Ethereum mainnet.
privateKeyYesPrivate key of the token owner account in hex format (with or without 0x prefix). SECURITY: This is used only for transaction signing and is not stored.
toAddressYesThe recipient wallet address that will receive the tokens
tokenAddressYesThe contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77')
tokenIdYesThe ID of the specific token to transfer (e.g., '1234')

Implementation Reference

  • The main handler function for transferring ERC1155 tokens. It resolves addresses, prepares the wallet client, and executes safeTransferFrom on the contract.
    export async function transferERC1155( tokenAddressOrEns: string, toAddressOrEns: string, tokenId: bigint, amount: string, privateKey: string | `0x${string}`, network: string = 'ethereum' ): Promise<{ txHash: Hash; tokenId: string; amount: string; }> { // Resolve ENS names to addresses if needed const tokenAddress = await resolveAddress(tokenAddressOrEns, network) as Address; const toAddress = await resolveAddress(toAddressOrEns, network) as Address; // Ensure the private key has 0x prefix const formattedKey = typeof privateKey === 'string' && !privateKey.startsWith('0x') ? `0x${privateKey}` as `0x${string}` : privateKey as `0x${string}`; // Create wallet client for sending the transaction const walletClient = getWalletClient(formattedKey, network); const fromAddress = walletClient.account!.address; // Parse amount to bigint const amountBigInt = BigInt(amount); // Send the transaction const hash = await walletClient.writeContract({ address: tokenAddress, abi: erc1155TransferAbi, functionName: 'safeTransferFrom', args: [fromAddress, toAddress, tokenId, amountBigInt, '0x'], account: walletClient.account!, chain: walletClient.chain }); return { txHash: hash, tokenId: tokenId.toString(), amount }; }
  • ABI fragment for ERC1155 safeTransferFrom and balanceOf functions used in the transfer handler.
    const erc1155TransferAbi = [ { inputs: [ { type: 'address', name: 'from' }, { type: 'address', name: 'to' }, { type: 'uint256', name: 'id' }, { type: 'uint256', name: 'amount' }, { type: 'bytes', name: 'data' } ], name: 'safeTransferFrom', outputs: [], stateMutability: 'nonpayable', type: 'function' }, { inputs: [ { type: 'address', name: 'account' }, { type: 'uint256', name: 'id' } ], name: 'balanceOf', outputs: [{ type: 'uint256' }], stateMutability: 'view', type: 'function' } ] as const;

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcpdotdirect/evm-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server