Verified wallets for users can be created either using a dynamically generated mnemonic or by importing mnemonics for an existing private key for the user on a supported ethereum network.
//Common Jsconst { VerifiedWallet,Provider } =require('@verified-network/verified-sdk'); //ES Moduleimport { VerifiedWallet, Provider } from'@verified-network/verified-sdk'/** Step 1: Create Verified Wallet **///Option 1: Generate new Mnemonics and WalletconstinvestorMnemonics=awaitVerifiedWallet.generateMnemonics()constinvestorWallet=awaitVerifiedWallet.importWallet(menmonics)//Option 2: using existing wallet mnemonicsconstinvestorMnemonics='your wallet mnemonics'constinvestorWallet=awaitVerifiedWallet.importWallet(investorMnemonics); /** Step 2: Set Provider for Wallet **///Option 1: using Default Providers by ethers.js(for networks like mainnet, sepolia, ropstan, polygon e.t.c)constdefaultProviderNetwork='sepolia'// or any other default provider network of your choice.//Network/chain id(number) can be used in place of network name, for example: const defaultProviderNetwork = 11155111 // where number 11155111 is chain id for sepolia. any other chain id of default provider network can be used.
constinvestorWalletProvider=investorWallet.setProvider(Provider.defaultProvider(defaultProviderNetwork) )//Option 2: using custom providers(infura and alchemy)constnetwork='sepolia'// or any other network of your choice.//Network/chain id(number) can be used in place of network name, for example:constnetwork=11155111// where number 11155111 is chain id for sepolia, any other chain id can be used.//For infura; to get api key and enable networks checout: https://www.infura.io/constINFURA_API_KEY='your infura api key'constinvestorWalletProvider=investorWallet.setProvider(Provider.infuraProvider(network,INFURA_API_KEY) )//For alchemy; to get api key and enable networks checout: https://www.alchemy.com/constALCHEMY_API_KEY='your alchemy api key'constinvestorWalletProvider=investorWallet.setProvider(Provider.alchemyProvider(network,ALCHEMY_API_KEY) )
Above, the investor wallet provider can be used to initialize Verified contracts and interact with them by calling various functions on contracts.
/** Import contract **///Common Jsconst { Client,contractAddress } =require('@verified-network/verified-sdk'); //ES Moduleimport { Client, contractAddress } from'@verified-network/verified-sdk'/** get chainId **/constconectedNetwork=awaitinvestorWalletProvider.getNetwork();constchainId=conectedNetwork.chainId;/** fetch contract address **///All verified contracts addresses can be fetched from contractAddress objectconstnetworkContractAddresses= contractAddress[chainId]; //All verified contract addresses on connected networkconstclientContractaddress=networkContractAddresses.Client; //Client contract address/** Initialize Contract **/constclientContract=newClient(investorWalletProvider, clientContractaddress);/** Interact with contract **/constinvestorAddres=awaitinvestorWallet.getAddress() //get user addressawaitclientContract.getRole(investorAddres);
Wallets from web brower extensions/wallets of any choice like Metamask, Coinbase wallet e.t.c can be used with Verified Sdk to interact with Verified Contracts.
/** install ethers: npm install --save ethers **///Common Jsconst { ethers } =require('ethers');//ES Moduleimport { ethers } from'ethers';/** Step 1: Get Proider from browser wallet **///MetaMask injects provider as window.ethereum//Any provider by web wallet of choice can be usedconstwebWalletProvider=window.ethereum; //convert to ethers.js providerconstprovider=newethers.providers.Web3Provider(webWalletProvider);//other ethers provider methods exists that will work //with any provider of choice checkout: https://docs.ethers.org/v5/getting-started//** Step 2: Connect and get signer to initialise contracts **/// MetaMask requires requesting permission to connect users accounts//Any connection method for any web browser of choice can be used;constconnectedAccounts=awaitprovider.send("eth_requestAccounts", []); constsigner=provider.getSigner()
Above, the signer can be used to initialize Verified contracts and interact with them by calling various functions on contracts.
/** Import contract **///Common Jsconst { Client,contractAddress } =require('@verified-network/verified-sdk'); //ES Moduleimport { Client, contractAddress } from'@verified-network/verified-sdk'/** get chainId **/constconectedNetwork=awaitprovider.getNetwork();constchainId=conectedNetwork.chainId;/** fetch contract address **///All verified contracts addresses can be fetched from contractAddress objectconstnetworkContractAddresses= contractAddress[chainId]; //All verified contract addresses on connected networkconstclientContractaddress=networkContractAddresses.Client; //Client contract address/** Initialize Contract **/constclientContract=newClient(signer, clientContractaddress);/** Interact with contract **/constinvestorAddres= connectedAccounts[0] //get first account connected from web walletawaitclientContract.getRole(investorAddres);
Certain contracts are proxies that indirect calls to concrete implementations. For example, cash tokens representing different currencies all have the same behavior and are produced by a cash token factory. In such cases, the contract needs to be parameterized (in this case, with a currency contract's address) before use.
Optionally, all the contract Calls take in an additional parameter: options?: { gasPrice: number, gasLimit: number } You can configure the gasPrice and gasLimit using this parameter as the last parameter to the contractCall function. Example: contract.function(arg 1, arg2, options) Where, options = {gasPrice: XXX, gasLimit: YYY}