The @rsksmart/safe-transactions-sdk package facilitates the creation of ERC721 transactions.
The ERC721TransactionBuilder
provides a set of methods related to ERC721 transactions.
safe: Safe
- a Safe instance
ERC721Token: Contract
- an ethers.js Contract representing the ERC721 tokenimport { ERC721TransactionBuilder } from "@rsksmart/safe-transactions-sdk";
const erc721TransactionBuilder = ERC721TransactionBuilder.create(
safe,
ERC721Token
);
from: string
- the address from
which transfers the token identified by tokenId
to: string
- the address will receive the token identified by tokenId
tokenId: BigNumber
- the id of the token will be transferred to address to
const safeTransaction = await erc721TransactionBuilder.transferFrom(
from,
to,
tokenId
);
IMPORTANT: Only the current owner, an authorized operator, or the approved address can call this method, see ERC721
safeTransferFrom
methods perform the same operation performed by transferFrom
and additionally, if the receiver is a contract address, they check if the contract address implements the interface ERC721TokenReceiver
and it returns the value 0x150b7a02
, obtained from bytes4(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
from: string
- the address from
which transfers the token identified by tokenId
to: string
- the address will receive the token identified by tokenId
tokenId: BigNumber
- the id of the token will be transferred to address to
data: string
- Optional, the data that will be sent to the receiver with the onERC721Received
call.await erc721TransactionBuilder.safeTransferFrom(
from,
to,
tokenId
);
It can be called with the optional data
parameter that will be sent to the receiver with the onERC721Received
call.
await erc721TransactionBuilder.safeTransferFrom(
from,
to,
tokenId
data
)
approved: string
- the address allowed to execute transfer operations on behalf of the ownertokenId: BigNumber
- the id of the tokenawait erc721TransactionBuilder.approve(approved, tokenId);
IMPORTANT: See ERC721 approval method
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 to true
to allow the operator to execute the operations on behalf of the owner, can be set to false
to disallow the approval.await erc721TransactionBuilder.setApprovalForAll(
operator,
approved
)
IMPORTANT: See ERC721 setApprovalForAll method
Go to top