RIF Multisig SDK - ERC721 Transactions
ERC721 Transactions
The @rsksmart/safe-transactions-sdk package facilitates the creation of ERC721 transactions.
The ERC721TransactionBuilder
provides a set of methods related to ERC721 transactions.
-
Initialize the ERC721TransactionBuilder.
- Parameters
safe: Safe
- a Safe instanceERC721Token: Contract
- an ethers.js Contract representing the ERC721 token
{:.snippet__parameters.snippet__parameters--lightgreen.border-bottom-0}
import { ERC721TransactionBuilder } from "@rsksmart/safe-transactions-sdk"; const erc721TransactionBuilder = ERC721TransactionBuilder.create( safe, ERC721Token );
{:.snippet__code.snippet__code--lightgreen.border-top-0}
- Parameters
-
TransferFrom transaction
- Parameters
from: string
- the addressfrom
which transfers the token identified bytokenId
to: string
- the address will receive the token identified bytokenId
tokenId: BigNumber
- the id of the token will be transferred to addressto
{:.snippet__parameters.snippet__parameters--lightgreen.border-bottom-0}
const safeTransaction = await erc721TransactionBuilder.transferFrom( from, to, tokenId );
{:.snippet__code.snippet__code--lightgreen.border-top-0}
IMPORTANT: Only the current owner, an authorized operator, or the approved address can call this method, see ERC721
{:.mt-3}
- Parameters
-
SafeTransferFrom transactions
- The
safeTransferFrom
methods perform the same operation performed bytransferFrom
and additionally, if the receiver is a contract address, they check if the contract address implements the interfaceERC721TokenReceiver
and it returns the value0x150b7a02
, obtained frombytes4(keccak256("onERC721Received(address,address,uint256,bytes)"))
. For further info, see ERC721
interface ERC721TokenReceiver { function onERC721Received(address _operator, address _from, uint256 _tokenId, bytes _data) external returns(bytes4); }
IMPORTANT: Only the current owner, an authorized operator, or the approved address can call this method, see ERC721
- Parameters
from: string
- the addressfrom
which transfers the token identified bytokenId
to: string
- the address will receive the token identified bytokenId
tokenId: BigNumber
- the id of the token will be transferred to addressto
data: string
- Optional, the data that will be sent to the receiver with theonERC721Received
call.
{:.snippet__parameters.snippet__parameters--lightgreen.border-bottom-0}
await erc721TransactionBuilder.safeTransferFrom( from, to, tokenId );
{:.snippet__code.snippet__code--lightgreen.border-top-0}
It can be called with the optional
data
parameter that will be sent to the receiver with theonERC721Received
call.await erc721TransactionBuilder.safeTransferFrom( from, to, tokenId data )
{:.snippet__code.snippet__code--lightgreen}
- The
-
Approve transaction
- Parameters:
approved: string
- the address allowed to execute transfer operations on behalf of the ownertokenId: BigNumber
- the id of the token
{:.snippet__parameters.snippet__parameters--lightgreen.border-bottom-0}
await erc721TransactionBuilder.approve(approved, tokenId);
{:.snippet__code.snippet__code--lightgreen.border-top-0}
IMPORTANT: See ERC721 approval method
{:.mt-3}
- Parameters:
-
SetApprovalForAll Transaction
-
It sets or unsets approval for a specific operator, that allows the operator to perform transfer operations on behalf of the owner.
-
Parameters
operator: string
- the address allowed/forbidden to execute transfer operations on behalf of the owner's tokensapproved: boolean
- set totrue
to allow the operator to execute the operations on behalf of the owner, can be set tofalse
to disallow the approval.
{:.snippet__parameters.snippet__parameters--lightgreen.border-bottom-0}
await erc721TransactionBuilder.setApprovalForAll( operator, approved )
{:.snippet__code.snippet__code--lightgreen.border-top-0}
IMPORTANT: See ERC721 setApprovalForAll method
{:.mt-3}
-