1.4.0 • Published 2 years ago

web3-accounts v1.4.0

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

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
 
1.4.0

2 years ago

1.3.11

2 years ago

1.3.15

2 years ago

1.3.9

2 years ago

1.3.8

2 years ago

1.3.7

2 years ago

1.3.6

2 years ago

1.3.5

2 years ago

1.3.3

2 years ago

1.3.1

2 years ago

1.3.0

2 years ago

1.2.31

2 years ago

1.2.30

2 years ago

1.2.28

2 years ago

1.2.27

2 years ago

1.2.26

2 years ago

1.2.25

2 years ago

1.2.23

2 years ago

1.2.22

2 years ago

1.2.21

2 years ago

1.2.20

2 years ago

1.2.19

2 years ago

1.2.18

2 years ago

1.2.17

2 years ago

1.2.16

2 years ago

1.2.15

2 years ago

1.2.14

2 years ago

1.2.13

2 years ago

1.2.12

2 years ago

1.2.11

2 years ago

1.2.10

2 years ago

1.2.9

2 years ago

1.2.8

2 years ago

1.2.7

2 years ago

1.2.6

2 years ago

1.2.5

2 years ago

1.2.4

2 years ago

1.2.3

2 years ago

1.2.2

2 years ago

1.2.1

2 years ago

1.2.0

2 years ago

1.1.34

2 years ago

1.1.33

2 years ago

1.1.32

2 years ago

1.1.31

2 years ago

1.1.30

2 years ago

1.1.29

2 years ago

1.1.28

2 years ago

1.1.27

2 years ago

1.1.26

2 years ago

1.1.25

2 years ago

1.1.24

2 years ago

1.1.23

2 years ago

1.1.22

2 years ago

1.1.21

2 years ago

1.1.20

2 years ago

1.1.19

2 years ago

1.1.18

2 years ago

1.1.17

2 years ago

1.1.16

2 years ago

1.1.15

2 years ago

1.1.13

2 years ago

1.1.12

2 years ago

1.1.11

2 years ago

1.1.10

2 years ago

1.1.9

2 years ago

1.1.8

2 years ago

1.1.7

2 years ago

1.1.6

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.0

2 years ago