RIF Safe Transactions SDK
npm i @rsksmart/safe-transactions-sdk
import { RawTransactionBuilder } from '@rsksmart/safe-transactions-sdk'
const ethersSafe: EthersSafe // from '@gnosis.pm/safe-core-sdk'
const rawTransactionBuilder = new RawTransactionBuilder(ethersSafe)
const tx = await rawTransactionBuilder.rawTransaction(
toAddress, // string
value, // string
data // string
)
import { ERC20TransactionBuilder } from '@rsksmart/safe-transactions-sdk'
const ethersSafe: EthersSafe // from '@gnosis.pm/safe-core-sdk'
const erc20TokenAddress: string //
const erc20TransactionBuilder = await ERC20TransactionBuilder.create(ethersSafe, erc20TokenAddress)
await erc20TransactionBuilder.transfer(
receiverAddress, // string
BigNumber.from(valueToTransfer)
)
IMPORTANT: It required prior approval, see ERC20 approval method
await erc20TransactionBuilder.transferFrom(
fromAddress, // string
toAddress, // string
BigNumber.from(valueToTransfer)
)
IMPORTANT: See ERC20 approval method and allowance
await erc20TransactionBuilder.approve(
spenderAddress, // string
allowance
)
IMPORTANT: The rejection transaction needs to be confirmed and executed like any other Multisig transaction.
import { rejectTx } from '@rsksmart/safe-transactions-sdk'
const rejectionTx = await rejectTx(safe, transaction)
import { ERC721TransactionBuilder } from '@rsksmart/safe-transactions-sdk'
const ethersSafe: EthersSafe // from '@gnosis.pm/safe-core-sdk'
const erc721TokenAddress: string //
const erc721TransactionBuilder = await ERC721TransactionBuilder.create(
ethersSafe,
erc721TokenAddress
)
IMPORTANT: Only the current owner, an authorized operator, or the approved address can call this method, see ERC721
await erc721TransactionBuilder.transferFrom(
fromAddress, // string
toAddress, // string
tokenId // BigNumber
)
The 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
await erc721TransactionBuilder.safeTransferFrom(
fromAddress, // string
toAddress, // string
tokenId // BigNumber
)
It can be called with the optional data
parameter that will be sent to the receiver with the onERC721Received
call.
await erc721TransactionBuilder.safeTransferFrom(
fromAddress, // string
toAddress, // string
tokenId // BigNumber
data // string
)
IMPORTANT: See ERC721 approval method
await erc721TransactionBuilder.approve(
approvedAddress, // string
tokenId // BigNumber
)
It sets or unsets approval for a specific operator. That would allow the operator to perform transfer operations on behalf of the owner.
IMPORTANT: See ERC721 setApprovalForAll method
await erc721TransactionBuilder.setApprovalForAll(
operatorAddress, // string
approved // boolean
)
Install dependencies:
npm i
npx hardhat node
Run unit tests with
npx hardhat test
npm run format
npm run lint
npm run build