Netwallet SDK
Name
netwallet-sdk
Installation
install with npm:
npm install netwallet-sdk --save
install with yarn:
yarn add netwallet-sdk
Usage
import { WalletApi } from 'netwallet-sdk';
const config = {
chainId : 4 //rinkeby-4, mainnet-1, ropsten-3
}
const wallet = new WalletApi(config);
/* creating provider using magic link rpc */
await magic.auth.loginWithMagicLink({email : "something@example.com"});
const provider = new ethers.providers.Web3Provider(magic.rpcProvider);
Wallet Operations
Get ETH Balance:
const account = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const balance = await wallet.balanceOfETH(provider, account);
Ether transfer:
const receiver = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amount = "0.01";
const tx = await wallet.transferEth(receiver, amount, provider);
Get ERC20 Balance:
const contractAddress = "0xb5B0cDBf3b42DDEBfaA1Fe95A79d29854F325eD3";
const account = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
await wallet.balanceOfERC20(provider, account, contractAddress);
ERC20 transfer:
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const amount = "1999999999999999999";
const contractAddress = "0xb5B0cDBf3b42DDEBfaA1Fe95A79d29854F325eD3";
await wallet.transferERC20(to, amount, contractAddress, provider);
Get ERC721 Balance:
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
const account = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
await wallet.balanceOfERC721(provider, account, contractAddress);
ERC721 transfer:
const from = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const tokenId = 1;
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await wallet.transferERC721(from, to, tokenId, contractAddress, provider);
ERC1155 balance:
const userAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenId = "1";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await wallet.getERC1155Balance(userAddress, tokenId, contractAddress, provider);
Get Balances of multiple tokens ERC1155:
const accounts = ["0x42681cC5478a619e36a85ddCF583DC750a690ed1", "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5"];
const ids = ["1", "2"];
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await wallet.getBalanceOfBatch(accounts, ids, contractAddress, provider);
Set Approval for All ERC1155:
const operator = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const approved = true;
await wallet.setApprovalForAll(operator, approved, contractAddress, provider);
Get tokenURI:
const tokenId = "1";
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
await wallet.getERC1155TokenData(provider, tokenId, contractAddress);
ERC1155 transfer:
const from = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const id = 1;
const amount = 1;
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
const data = "";
await wallet.transferERC1155(from, to, id, amount, data, contractAddress, provider);
Get NFTs:
const owner = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const chain = "rinkeby"
await wallet.getNFTs(owner, chain)
Get ERC20 tokens:
const owner = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const chain = "rinkeby";
await wallet.getERC20(owner, chain);
GetTransactionHistory:
const addr = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
await wallet.getTransfers(addr); // get the token details from raw contract object
GetERC20TransferGasEstimate:
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const amount = 100;
await wallet.erc20TransferGasEstimate(contractAddress, to, amount);
GetETHTransferGasEstimate:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amountInETH = "0.01";
await wallet.ethTransferGasEstimate(to, amountInETH);
GetNFTTransferGasEstimate:
const from = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const id = 1;
const amount = 1;
const contractAddress = "0xaD8A70DF656f38410640F7102C724Cbf8cC4b932";
const data = "";
await wallet.nftTransferGasEstimate(from, to, id, amount, data, contractAddress);
Gas Estimate for Mecum contract:
const contractAddress = "0xF71FECC1740299b64bb096B6353f953EE500B636";
const functionName = "mint";
const to = "0x323442006196921922d33004588e641e065ef43d";
const amount = "100";
const data = "0x";
const tokenURI = "abcd";
const maxSupply = "1000";
const assetId = "1";
await wallet.getGasEstimateForMecum(contractAddress, provider, functionName, to, amount, data, tokenURI, maxSupply, assetId);
Usage for NFT Lens
Mint:
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const amount = "100";
const tokenURI = "https://ipfs.io/ipfs/QmP9h59UNm6YiYEwkxzd5U9ChFiqciNnq7QPvK4a3KkHNk";
const data = "0x";
await wallet.mintNFTFromLens(to, amount, tokenURI, provider);
Vault Registry Operations
Deploy Vault:
const dailyLimit = "10000" //value in Wei
const owner = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const heir = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const guadians = ["0x42681cC5478a619e36a85ddCF583DC750a690ed1","0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5","0xaD8A70DF656f38410640F7102C724Cbf8cC4b932"];
await wallet.deployVault(dailyLimit, owner, heir, guardians, provider)
Get Guardian Vaults:
const guardian = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
await wallet.getGuardianVaults(guardian, provider);
Get Vaults:
const owner = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
await wallet.getVaults(owner, provider);
Vault Operations
Change Heir:
const newHeir = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.changeHeir(newHeir, contractAddress, provider);
Create Add or Remove Guardian Request:
const guardian = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const removeRequest = true //true for removing a guardian and false for adding a guardian
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.createAddOrRemoveGuardianRequest(guardian, removeRequest, contractAddress, provider);
Create Change Owner Request:
const newOwner = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.createChangeOwnerRequest(newOwner, contractAddress, provider);
Deposit Ether to the Vault:
const amount = "0.01" //value in ether
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.depositEther(amount, contractAddress, provider);
Get Add or Remove Guardian Request Length:
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getAddOrRemoveGuardiansRequestsLength(contractAddress, provider);
Get Vault Details This function will return an array of 4 elements -
- balance of contract in Wei
- Daily Limit of Withdrawal in Wei
- address of the owner
- address of heir
- list of guardians
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getVaultDetails(contractAddress, provider);
Get Withdraw Requests Length:
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getWithdrawRequestsLength(contractAddress, provider);
Get Owner Change Requests Length:
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getchangeOwnerRequestsLength(contractAddress, provider);
Opt Out of the Vault:
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.optOutOfVault(contractAddress, provider);
Pass Vault to Heir:
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.passVaultToHeir(contractAddress, provider);
Transfer ERC20 from Vault:
const tokenAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const to = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const amount = "10000000000000"; //in basic uint of the ERC20
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.transferERC20FromVault(tokenAddress, to, amount, contractAddress, provider);
Vote on Add/Remove Guardian Request:
const requestId = 0;
const vote = true; //true to approve a request, false to reject a request
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.voteAddOrRemoveGuardianRequest(requestId, vote, contractAddress, provider);
Vote on Owner Change Request:
const requestId = 0;
const vote = true; //true to approve a request, false to reject a request
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.voteChangeOwnerRequest(requestId, vote, contractAddress, provider);
Vote on Withdraw Request:
const requestId = 0;
const vote = true; //true to approve a request, false to reject a request
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.voteWithdrawRequest(requestId, vote, contractAddress, provider);
Withdraw Ether from Vault:
const amount = "10000000000000" // amount to be withdrawn in Wei
const receiver = "0x1C67f57e0184708A3530d0C8ef3dcF4614e3edd5";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.withdrawEther(amount, receiver, contractAddress, provider);
Get withdraw request from id:
const id = "0";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getWithdrawRequestById(id, contractAddress, provider);
Get change owner request from id:
const id = "0";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getChangeOwnerRequestById(id, contractAddress, provider);
Get add/remove request from id:
const id = "0";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getAddOrRemoveRequestById(id, contractAddress, provider);
Usage for NFT-1155
Bulk Mint:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amounts = ["10", "30", "50"];
const data = "0x123";
const maxsupplies = ["15", "40", "60"];
const assetIds = ["1", "2", "3"];
const tokenURIs = ["https://ipfs.io/ipfs/QmP9h59UNm6YiYEwkxzd5U9ChFiqciNnq7QPvK4a3KkHNk", "https://ipfs.io/ipfs/QmP9h59UNm6YiYEwkxzd5U9ChFiqciNnq7QPvK4a3KkHNk", "https://ipfs.io/ipfs/QmP9h59UNm6YiYEwkxzd5U9ChFiqciNnq7QPvK4a3KkHNk"];
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856"
await wallet.bulkMint(to, amounts, data, maxsupplies, assetIds, tokenURIs, contractAddress, provider);
Bulk Mint Existing Token IDs:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amounts = ["10", "30", "50"];
const data = "0x123";
const tokenIds = ["0", "1", "2"];
const assetIds = ["0", "1", "2"];
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.bulkMintExistingTokenIds(to, amounts, data, tokenIds, assetIds, contractAddress, provider);
Bulk Transfer:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenIds = ["0", "1", "2"];
const amounts = ["10", "30", "50"];
const data = "0x123";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.bulkTransfer(to, tokenIds, amounts, data, contractAddress, provider);
Get Token URI:
const tokenId = "0";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.getTokenURI(tokenId, contractAddress, provider);
Mint:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amount = "10";
const data = "0x123";
const tokenURI = "https://ipfs.io/ipfs/QmP9h59UNm6YiYEwkxzd5U9ChFiqciNnq7QPvK4a3KkHNk";
const maxsupply = "15";
const assetId = "1";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.mint(to, amount, data, tokenURI, maxsupply, assetId, contractAddress, provider);
Mint Existing Token Id:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const amount = "10";
const data = "0x123";
const tokenId = "0";
const assetId = "1";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.mintExistingTokenId(to, amount, data, tokenId, assetId, contractAddress, provider);
Transfer:
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenId = "0";
const amount = "10";
const data = "0x123";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.transfer(to, tokenId, amount, data, contractAddress, provider);
Update Base URI:
const baseURI = "https://ipfs.io/ipfs/";
const contractAddress = "0x18E5ade8a0884c398A1B163726FBB831DF084856";
await wallet.updateBaseURI(baseURI, contractAddress, provider);
Usage for Artemis Marketplace
import {ArtemisMarketPlace} from 'netwallet-sdk';
const auction = new ArtemisMarketPlace();
Start an auction:
const sellToken = "0x274c4e305A5cFF337d6833aE51339bbf86FA60c8";
const sellTokenValue = "10";
const sellTokenId = "1";
const buyAsset = "0x0000000000000000000000000000000000000000";//if buy asset is ETH, else ERC20 address
const minimalPrice = "1000000000000000"; // (0.001ETH) in basic unit of the buying asset
const duration = "1000"; //in seconds
const buyOutPrice = "200000000000000000"; // (0.2ETH) in basic unit of the buying asset
await auction.startAuction(sellToken, sellTokenValue, sellTokenId, buyAsset, minimalPrice, duration, buyOutPrice, provider)
Buyout Auction using ERC20:
const auctionId = "1";
const bidAmount = "200000000000000000"; // (0.2 for ERC20 Token with 18 decimals) in basic unit of the buying asset
await auction.buyOut(auctionId, bidAmount, provider);
Bid on an Auction Item using ERC20:
const auctionId = "1";
const bidAmount = "1000000000000000"; // (0.001 for ERC20 Token with 18 decimals) in basic unit of the buying asset
await auction.bid(auctionId, bidAmount, provider);
Buyout Auction using ETH:
const auctionId = "1";
const bidAmount = "200000000000000000"; // 0.2ETH in Wei
await auction.buyOutWithETH(auctionId, bidAmount, provider);
Bid on an Auction Item using ETH:
const auctionId = "1";
const bidAmount = "1000000000000000"; // 0.001ETH in Wei
await auction.bidWithEth(auctionId, bidAmount, provider);
Cancel an auction:
const auctionId = "1";
await auction.cancel(auctionId, provider);
Finish an auction:
const auctionId = "1";
await auction.finishAuction(auctionId, provider);
Get Next Minimal Bid for an Auction:
const auctionId = "1";
await auction.getMinimalNextBid(auctionId, provider);
Get Auction by Id:
const auctionId = "1";
await auction.getAuctionById(auctionId, provider);
Check Auction Existence:
const auctionId = "1";
await auction.checkAuctionExistence(auctionId, provider);
Check Auction Range Time:
const auctionId = "1";
await auction.checkAuctionRangeTime(auctionId, provider);
Get Protocol Fee:
await auction.getProtocolFee(provider);
Get current buyer:
const auctionId = "1";
await auction.getCurrentBuyer(auctionId, provider);
Get Minimal Duration:
await auction.getMinimalDuration(provider);
Get Active Marketplace Items:
await auction.getMarketplaceItemList(provider);
Get current Auction Id:
await auction.getCurrentAuctionId(provider);
Usage for Airdrop
const config = {
chainId : 4
}
const airdrop = new Airdrop(config);
Check if user has already claimed NFT
const userAddress = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenId = "1";
await airdrop.hasClaimed(userAddress, tokenId, provider);
Get Token Id
await airdrop.getTokenId(provider);
Mint Airdrop NFT (from API):
const maxAmount = "1000";
const data = "0x";
const tokenURI = "https://ipfs.io/ipfs/QmTN32qBKYqnyvatqfnU8ra6cYUGNxpYziSddCatEmopLR";
await airdrop.mintAirdropNFT(maxAmount, data, tokenURI, wallet);
Transfer Airdrop NFT (from API):
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenId = "1";
const data = "0x";
await airdrop.transferAirdropNFT(to, data, tokenId, wallet);
Mint Airdrop NFT (from Frontend):
const maxAmount = "1000";
const data = "0x";
const tokenURI = "https://ipfs.io/ipfs/QmTN32qBKYqnyvatqfnU8ra6cYUGNxpYziSddCatEmopLR";
await airdrop.mintFromAdmin(maxAmount, data, tokenURI);
Transfer Airdrop NFT (from Frontend):
const to = "0x42681cC5478a619e36a85ddCF583DC750a690ed1";
const tokenId = "1";
const data = "0x";
await airdrop.transferFromAdmin(to, tokenId, data);
Usage for ENS
const provider = new ethers.providers.AlchemyWebSocketProvider("rinkeby", <API_KEY>);
Get ENS Name from Address:
const address = "0x3E0e5C49008c6Ef7CF08a7c458C50498E1455851"
await wallet.getEnsName(address, provider)
Get Address from ENS name:
const ensName = "rizzy" // or "rizzy.eth"
await wallet.getEnsAddress(ensName, provider)
Check ENS Name Availabilty:
const checkName = "rizzy" // do not send "rizzy.eth"
await wallet.checkAvailable(checkName, provider)
Usage for Pinata
Create instance of IPFS:
import {IpfsApi} from "netwallet-sdk" ;
const config = {
apiKey: "your_api_key",
secretApiKey: "your_secret_api_key",
}
const ipfsClient = new IpfsApi( config ) ;
Upload and Pin File to IPFS:
let file = event.target.files[ 0 ] ;
await ipfsClient.uploadFileToIPFS(file) ;
Upload and Pin File to IPFS from react native:
await ipfsClient.uploadFileReactNative(formData, customHeaders);
Upload and Pin File with category to IPFS:
let file = event.target.files[ 0 ] ;
await ipfsClient.uploadFileWithCategoryToIPFS( file , "custom-file-category" )
Upload and Pin json data (not file) to IPFS:
const jsonData = {
pinataMetadata: {
name: "my-custom-name"
} ,
pinataContent: {
message: "Hey there! I am Rishabh Mishra"
}
};
await ipfsClient.uploadJsonToIPFS( jsonData ) ;
Retrieve Pinned Content from IPFS:
/*
retrieveContentFromIPFS(cid) is a static function.
Call it using a class name an not with instance.
See example below.
*/
let cid = "QmWBiLYnDbKNpJpyngyPwD12CsaHRad3abdDVVcw3VYHLX" ;
await IpfsApi.retrieveContentFromIPFS( cid ) ;
License
MIT