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
| Name | Required | Description | Default |
|---|---|---|---|
| amount | Yes | The quantity of tokens to send (e.g., '1' for a single NFT or '10' for 10 fungible tokens) | |
| network | No | Network name (e.g., 'ethereum', 'optimism', 'arbitrum', 'base', 'polygon') or chain ID. ERC1155 tokens exist across many networks. Defaults to Ethereum mainnet. | |
| privateKey | Yes | Private 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. | |
| toAddress | Yes | The recipient wallet address that will receive the tokens | |
| tokenAddress | Yes | The contract address of the ERC1155 token collection (e.g., '0x76BE3b62873462d2142405439777e971754E8E77') | |
| tokenId | Yes | The ID of the specific token to transfer (e.g., '1234') |
Implementation Reference
- src/core/services/transfer.ts:389-432 (handler)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 }; }
- src/core/services/transfer.ts:91-115 (helper)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;