rishabh-digiffer-wallet-reactjs
v1.0.3
Published
DigifferWallet is a JavaScript library designed to integrate Google OAuth login for creating and managing blockchain wallets. It provides a simple interface to show a login popup, handle Google login responses, and perform various wallet-related operation
Downloads
9
Readme
DigifferWallet
DigifferWallet is a JavaScript library designed to integrate Google OAuth login for creating and managing blockchain wallets. It provides a simple interface to show a login popup, handle Google login responses, and perform various wallet-related operations such as creating wallets, getting balances, and interacting with smart contracts.
Table of Contents
Installation
Install the package using npm or yarn:
Using NPM
npm install digiffer-wallet-web
Using Yarn
yarn add digiffer-wallet-web
Then, include the DigifferWallet
class in your project.
Usage
Initialization
Initialize the DigifferWallet
class with the necessary configuration:
import DigifferWallet from './path/to/DigifferWallet';
const config = {
hostUrl: 'https://your-api-host.com',
apiKey: 'your-api-key',
googleClientID: 'your-google-client-id'
};
const digifferWallet = new DigifferWallet(config);
Handle Login
To display the login popup, call the initLogin
method with a response handler function:
const handleLogin = async () => {
try {
digifferWallet.initLogin((response) => {
console.log('Google login response:', response);
});
} catch (error) {
console.error('Error in Login', error);
}
};
<button onClick={handleLogin}>Login </button>
API Methods
DigifferWallet provides several methods for interacting with the wallet:
getWalletAddress(requestData)
Get the wallet address for the given user.
const requestData = { "sub_id": "user-sub-id" };
const walletData = await digifferWallet.getWalletAddress(requestData);
console.log(walletData);
getBalance(requestData)
Get the balance of the wallet.
const requestData = { "sub_id" : "user-sub-id" } // for Native token balance
const requestData = { "sub_id" : "user-sub-id", "token": "0xe954c2d9ff2a4d260dcd32386b1f9fc8135d2522" } // Custom token balance
const balance = await digifferWallet.getBalance(requestData);
console.log(balance);
readContract(requestData)
Read data from a smart contract.
const requestData= { "sub_id": "user-sub-id", "contractAddress": "Contract Address Here", "contractABI": [], "functionName": "contract-function-name", "functionArguments": "Function aruguments (Leave Blank if empty) " }
const contractData = await digifferWallet.readContract(requestData);
console.log(contractData);
writeContract(requestData)
Write data to a smart contract.
const requestData = { "sub_id": "user-sub-id", "contractAddress": "Contract Address Here", "contractABI": [], "functionName": "contract-function-name", "functionArguments": [] }
const writeResponse = await digifferWallet.writeContract(requestData);
console.log(writeResponse);
writeMultipleOnContract(requestData)
Perform multiple transactions on a smart contract.
const requestData = { "sub_id": "user-sub-id", "transactionData": [
{
"contractAddress": "Contract Address Here", "contractABI": [], "functionName": "contract-function-name", "functionArguments": []
}
{
"contractAddress": "Contract Address Here", "contractABI": [], "functionName": "contract-function-name", "functionArguments": []
}
]}
const batchResponse = await digifferWallet.writeMultipleOnContract(requestData);
console.log(batchResponse);
License
This project is licensed under the MIT License.