Is there a way to send an 1155 or 731 nft in one transaction together with a token(erc-20) and if yes could someone provide an example
Is there a way to send an 1155 or 731 nft in one transaction together with a token(erc-20) and if yes could someone provide an example
You can create a muticall contract that wraps both token transfers into one transaction.
Example:
pragma solidity ^0.8;
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC721/IERC721.sol";
contract MyContract {
IERC20 erc20Token = IERC20(address(0x123));
IERC721 nftCollection = IERC721(address(0x456));
function sendFromThisContract(address to, uint256 erc20Amount, uint256 nftId) external {
erc20Token.transfer(to, erc20Amount);
nftCollection.transferFrom(address(this), to, nftId);
}
function sendFromUser(address to, uint256 erc20Amount, uint256 nftId) external {
erc20Token.transferFrom(msg.sender, to, erc20Amount);
nftCollection.transferFrom(msg.sender, to, nftId);
}
}
In case of sendFromUser(), the user needs to send additional 2 transactions to be able to perform this action:
MyContract to operate the user's tokensMyContract to operate the user's specific token ID (or all tokens)It is not technically possible to transfer multiple tokens (with different contract addresses) in one transaction without an intermediary or without the approvals. This is because when you're sending a token, you're sending a transaction to the token/collection contract. And by design, a transaction can have only one recipient.