Completing Transactions

View Assets in the Smart Account

Once you have access to your Halliday Smart Account, 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);