So i am Creating a ERC1155 Token Like This
contract Tokens is ERC1155 {
address public owner;
uint256 public tokenCount;
address[] recipients;
constructor() public ERC1155("erctoken") {
owner = msg.sender;
}
function mint(uint256 initialSupply) external {
tokenCount++;
uint256 tokenId = tokenCount;
_mint(msg.sender, tokenId, initialSupply , "");
}
}
Now i want to make a function in another contract in which the parameters will be token address, amount to send, and sender address list, so i want to transfer a 1000 ERC1155 tokens to 1000 different address, i want this function to accept any ERC1155 token, Here is the code i have written so far.
contract BulkSender {
using SafeMath for uint;
address public receiverAddress;
function coinSendSameValue(address _tokenAddress, address[] memory _to, uint256 _value, uint256 _id) payable public {
address _sender = msg.sender;
ERC1155 token = ERC1155(address(_tokenAddress));
for (uint8 i = 1; i < _to.length; i++) {
token.setApprovalForAll(_sender, true);
token.safeTransferFrom(_sender,_to[i],_id,_value,"0xcdcd77c000000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001");
}
}
function getBalance(address _tokenAddress ,address _AccountAddress , uint _id) public returns (uint256) {
return ERC1155(address(_tokenAddress)).balanceOf(_AccountAddress, _id);
}
/*
* set receiver address
*/
function setReceiverAddress(address _addr) public {
require(_addr != address(0));
receiverAddress = _addr;
}
/*
* get receiver address
*/
function getReceiverAddress() public view returns(address) {
return receiverAddress;
}
}
Let me know if this is the right approach and this is the error i am facing
transact to Tokens.coinSendSameValue errored: VM error: revert.
revert
The transaction has been reverted to the initial state.
Reason provided by the contract: "ERC1155: caller is not owner nor approved".
Debug the transaction to get more information.