Getting Started With Social Login
Get started with the Halliday SDK by leveraging social-login functionality to quickly create a Smart Account and run a gas-sponsored transaction.
See our demo repo for a working example.
Create a Smart Account with a Social Login
Halliday's Social Login flow offers an easy onboarding experience for users via their social accounts and emails. To integrate our social login SDK, first install the halliday-sdk:
npm install halliday-sdk
or
yarn add halliday-sdk
After initializing our SDK, you can present users with the options to log in via Google, Facebook, Twitter, and email. This creates a non-custodial Halliday Smart Account that is cryptographically linked with their social login. Users have access to this account as long as they authenticate with the same social login. The following example shows how to utilize social login to access your Halliday Smart Account:
import {Halliday, BlockchainType} from "halliday-sdk";
// Initialize the Halliday client.
const hallidayClient = new Halliday(
"HALLIDAY_API_KEY",
BlockchainType.DFK, // Specifying blockchainType is optional - defaults to Mumbai
true, // This is an optional argument that makes the SDK interact with your testing environment
{
verifierClientId: "VERIFIER_CLIENT_ID"
},
);
// Call logInWithGoogle, logInWithFacebook, logInWithTwitter to have the user log in.
// These will redirect the user to the corresponding website to log in. Once they log
// in, they will be redirected back to your original page.
hallidayClient.logInWithGoogle();
// Call logInWithEmailOTP to have the user log in via a one-time passcode that is
// sent to the provided email address. This will also redirect the user to a separate
// website to confirm the OTP. Once they verify the OTP, they will be redirected back
// to your original page.
hallidayClient.logInWithEmailOTP("[email protected]");
// Call getUserInfo() to see whether or not the user is logged in, either from
// being redirected back here or from not signing out from a previous session.
const userInfo = await hallidayClient.getUserInfo();
// You can register the user on your backend, using your own endpoints. The below is a
// placeholder example.
const userInGameId = yourApp.createNewUser(
userInfo.name,
userInfo.email,
userInfo.signer.address
);
// You can also immediately start signing transactions.
const signer = userInfo.signer;
const signedMessage = await signer.signMessage("message");
// To get or create the Halliday Smart Account, call getOrCreateHallidayAAWallet.
// This will get the user's smart account for the blockchain you specified in the constructor.
const hallidayAccount = await hallidayClient.getOrCreateHallidayAAWallet(userInGameId);
const hallidayAccountAddress = wallet.account_address;
// Log out!
await hallidayClient.logOut();
View Assets in the Smart Account
Once you have access to your Halliday Smart Account via social login, you can view assets and balances in the smart account as demonstrated below:
// Get NFTs in the Halliday Smart Account.
const assets = await hallidayClient.getAssets(userInGameId);
// Get ERC20 balances in the Halliday Smart Account.
const balances = await hallidayClient.getBalances(userInGameId);
Create a transferAsset Transaction
To transfer an ERC721 token from one account to another, you can construct and send the transaction as demonstrated below:
// Transfer an NFT to a different user, with gas sponsored by the paymaster.
const transferAssetTxInfo = await hallidayClient.transferAsset({
from_in_game_player_id: userInGameId, // Your user's id in your application
to_in_game_player_id: "other_player_id", // Other user's id in your application
collection_address: "0xeeaf9e39057002eae4bea8bb4e65b01a9cfd59be", // ERC721 token contract address
token_id: "3988", // Token id to transfer
sponsor_gas: true, // Send with gas sponsorship
});
console.log(transferAssetTxInfo.status, transferAssetTxInfo.on_chain_id);
Create a transferBalance Transaction
To transfer an ERC20 token or native token from one account to another, you can construct and send the transaction as demonstrated below:
// Transfer an ERC20 to a different user, with gas sponsored by the paymaster.
const balanceTransferTxInfo = await hallidayClient.transferBalance({
from_in_game_player_id: userInGameId, // Your user's id in your application
to_in_game_player_id: "other_player_id", // Other user's id in your application
token_address: "0x0799ea468f812e40dbabe77b381cac105da500cd", // ERC20 token contract address
value: "100000000000000000", // Amount of token to transfer, in the lowest decimal demonition of the token
sponsor_gas: true, // Send with gas sponsorship
});
console.log(balanceTransferTxInfo.status, balanceTransferTxInfo.on_chain_id);
Create a Transaction to Call Any Smart Contract Function
To call any on-chain smart contract function, you can construct and send the transaction as demonstrated below:
// Call an arbitrary contract.
const contractAddress = '0x1f6557356bfb310a556300a36fb18f54fb4791b1';
// The contract's ABI
const contractAbi = [...]; // Replace with your contract's ABI
// Create an instance of the contract
const contract = new ethers.Contract(contractAddress, contractAbi, signer);
// Get the calldata for a contract call
const calldata = contract.interface.encodeFunctionData('someFunction', ['arg1', 'arg2']);
// Call the contract, with gas sponsored by the paymaster.
const contractCallTxInfo = await hallidayClient.callContract({
from_in_game_player_id: userInGameId, // Your user's id in your application
target_address: contractAddress,
value: "0",
calldata,
sponsor_gas: true,
});
console.log(contractCallTxInfo.status, contractCallTxInfo.on_chain_id);
Updated 4 days ago