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

web3-accounts

v1.4.0

Published

Javascript SDK for web3 accounts

Downloads

139

Readme

web3-accounts

Common utils for account operation ERC20 ERC721 ERC1155

Installation

In your project, run:

npm i web3-accounts

Getting Started

const privateKeys=[]

import { Web3Accounts} from "web3-accounts"; 
const account = new Web3Accounts({
    chainId:1,
    address: "0x548427d1418066763173dd053D9d1AE32D161310",
    privateKeys: privateKeys,
})
const sign =await account.signMessage('Hello Web3')

The signature method

    ecSignMessage(message: string, privateKey?: string)  

    async signMessage(message: string | Bytes) 

    async signTypedData(typedData: EIP712TypedData)
    const user = new Web3Accounts({
        chainId,
        address: seller,
        privateKeys: secrets.privateKeys,
    })
    const msg = 'hello web3'
    const ecSign = user.ecSignMessage(msg)
    const signature = await user.signMessage(msg)
    console.assert(joinECSignature(ecSign) == signature)

Approve and de-Approve

async approveERC20Proxy(tokenAddr: string, spender: string, allowance?: string)

async cancelERC20Approve(tokenAddr: string, operator: string)

async approveERC721Proxy(tokenAddr: string, operator: string)

async cancelERC721Approve(tokenAddr: string, operator: string)

async approveERC1155Proxy(tokenAddr: string, operator: string)

async cancelERC1155Approve(tokenAddr: string, operator: string)

async assetApprove(asset: Asset, operator: string, allowance?: string)
 const erc20Approve = await user.approveERC20Proxy(tokenAddr, seller, "200")
 await erc20Approve.wait()

Get basic asset information

async getGasBalances(account?: { address?: string, rpcUrl?: string })

async getTokenBalances(params: { tokenAddr: string, account?: string, rpcUrl?: string })

async getERC20Balances(erc20Addr: string, account?: string)

async getERC20Allowance(erc20Addr: string, spender: string, account?: string)

async getERC20Decimals(erc20Addr: string)

async getERC721Balances(to: string, tokenId: string, account?: string)

async getERC721OwnerOf(to: string, tokenId: string)

async getERC721Approved(to: string, operator: string, account?: string)

async getERC1155Balances(to: string, tokenId: string, account?: string)

async getERC1155Approved(to: string, operator: string, account?: string)

async getAssetApprove(asset: Asset, operator: string, account?: string)

async getTokenApprove(tokenAddr: string, spender: string, account?: string)

async getAssetBalances(asset: Asset, account?: string)

async getUserTokenBalance(token: { tokenAddr?: string, decimals?: number, account?: string, rpcUrl?: string})

async getUserTokensBalance(params: {
    tokens: {
        tokenAddr: string,
            decimals: number
    }[],
    account?: string,
    rpcUrl?: string
})
const erc721={
    tokenId: '27',
    tokenAddress: '0x56df6c8484500dc3e2fe5a02bed70b4969ffafdb',
    schemaName: 'erc721'
}
const bal721 = await user.getAssetBalances(erc721)
const erc1155 ={
    tokenId: '13',
    tokenAddress: '0x991a868aa7b0a9a24565ede2d8fe758874a6a217',
    schemaName: 'ERC1155'
} 
const bal1155 = await user.getAssetBalances(erc1155)

Transfer of assets

async assetTransfer(metadata: ExchangeMetadata, to: string)

async transfer(asset: Asset, to: string, quantity: number)
 const tx = await user.transfer(erc721, seller, 1)
 await tx.wait()

Weth transfer between eth

async wethBalances(account?: string)

async wethWithdraw(ether: string)

async wethDeposit(ether: string, depositFunc?: false)
    const wethBal = await user.wethBalances() 
    const wethWithdrawTx = await user.wethWithdraw(wethBal)
    await wethWithdrawTx.wait()

    const wethDepositTx = await user.wethDeposit(wethBal)
    await wethDepositTx.wait()

Type conversion funciton

  assetToMetadata(asset: Asset, quantity: string = "1", data?: string): ExchangeMetadata 

  metadataToAsset(metadata: ExchangeMetadata, data?: Asset): Asset  

  tokenToAsset(token: Token): Asset  

  tokenToMetadata(token: Token, quantity: string = "1", data?: string): ExchangeMetadata  

  transactionToCallData(data: PopulatedTransaction): LimitedCallSpec