npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rsksmart/safe-transactions-sdk

v1.0.0

Published

RIF Safe Transactions SDK

Downloads

11

Readme

npm i @rsksmart/safe-transactions-sdk

Raw transactions

RawTransactionBuilder initialization

import { RawTransactionBuilder } from '@rsksmart/safe-transactions-sdk'

const ethersSafe: EthersSafe // from '@gnosis.pm/safe-core-sdk'

const rawTransactionBuilder = new RawTransactionBuilder(ethersSafe)

Raw transaction creation

const tx = await rawTransactionBuilder.rawTransaction(
  toAddress, // string
  value, // string
  data // string
)

ERC20 Token transactions

ERC20TransactionBuilder initialization

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)

transfer

await erc20TransactionBuilder.transfer(
  receiverAddress, // string
  BigNumber.from(valueToTransfer)
)

transferFrom

IMPORTANT: It required prior approval, see ERC20 approval method

await erc20TransactionBuilder.transferFrom(
  fromAddress, // string
  toAddress, // string
  BigNumber.from(valueToTransfer)
)

approve

IMPORTANT: See ERC20 approval method and allowance

await erc20TransactionBuilder.approve(
  spenderAddress, // string
  allowance
)

Rejection transaction creation

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)

ERC721 Token transaction

ERC721TransactionBuilder initialization

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
)

transferFrom

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
)

safeTransferFrom

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
)

approve

IMPORTANT: See ERC721 approval method

await erc721TransactionBuilder.approve(
  approvedAddress, // string
  tokenId // BigNumber
)

setApprovalForAll

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
)

Run for development

Install dependencies:

npm i

Run a local network

npx hardhat node

Tests

Run unit tests with

npx hardhat test

Lint & formatting

npm run format
npm run lint

Build

npm run build