How to transfer ERC1155 tokens from a Smart Contract?

Hi, does anyoneknow how to transfer ERC1155 tokens from a smart contract? I keep getting the error "ERC1155: caller is not token owner or approved". Any help would be appreciated

You're not providing alot of information to go on.
ERC-1155 has a function called * safeTransferFrom(from, to, id, amount, data) you can call which will transfer a token from one person to another.

However from address will have to be the owner of the token id, of he/she would have need to have called * setApprovalForAll(operator, approved) to approve the msg sender to allow the transfer by the person calling the safeTransferFrom

agree with CryptoWorld...

let me add some points...

ERC1155: caller is not token owner or approved...

it happens because you want to transfer the tokens on behalf owner's wallet address. but the owner hasn't approved your wallet address to be an operator.

what you need to do is let the owner of the address call setApprovalForAll :

setApprovalForAll is to let you as the contract owner/address to be an operator to transfer the tokens on behalf of the owners.

example:
operator (address)
contract owner/admin or contract address

approved (bool)
true

that's it. hope it helps.

1 Like