Skip to content

Send Tokens

In this guide, you will learn how Web3 apps that integrate with the Arcana Auth SDK can use the standard Ethereum JSON RPC calls supported by the Arcana wallet and programmatically allow authenticated users to send native or custom tokens to another wallet address.

Receiving tokens

To receive tokens using the Arcana wallet, the app user can choose to use either the wallet account address or the QR code for an account. The account address or QR code must be shared with the sender in order to receive tokens. See how to manage token assets in the Arcana Auth SDK User Guide for details.

Prerequisites

  • Use the Arcana Developer Dashboard to register the app and obtain a unique Client ID required for integrating the app with the Arcana Auth SDK.

  • Follow the instructions to configure authentication providers before integrating the app with the Arcana Auth SDK.

  • Use the appropriate integration method as per the app type and integrate the app with the Arcana Auth SDK.

  • Add code in the integrated app to onboard users. The Web3 wallet operations can be invoked programmatically in an app only in the context of an authenticated user.

Steps

Make sure you have addressed the prerequisites before adding code to invoke any Web3 wallet operations supported by the Arcana wallet. After that, plug in the necessary code to set up requisite hooks for JSON/RPC standard Ethereum calls.

// Assuming Auth SDK is integrated and initialized
try {
  provider = auth.provider
  const connected = await auth.isLoggedIn()
  console.log({ connected })
  setHooks()
} catch (e) {
  // Handle exception case
}

// setHooks: Manage chain or account switch in Arcana wallet
function setHooks() {
  provider.on('connect', async (params) => {
    console.log({ type: 'connect', params: params })
    const isLoggedIn = await auth.isLoggedIn()
    console.log({ isLoggedIn })
  })
  provider.on('accountsChanged', (params) => {
    //Handle
    console.log({ type: 'accountsChanged', params: params })
  })
  provider.on('chainChanged', async (params) => {
    console.log({ type: 'chainChanged', params: params })
  })
}

Send Transactions

Once the app is registered, configured, and integrated with the Arcana Auth SDK, the developers can add the code to enable sending tokens in the context of an authenticated app user. Use the 'sendTransaction' function as shown in the following code sample:

async function sendTransaction() {
  setRequest('eth_sendTransaction')
  const hash = await provider.request({
    method: 'eth_sendTransaction',
      params: [{
      from,
      gasPrice: 0,
      to: '0xE28F01Cf69f27Ee17e552bFDFB7ff301ca07e780',
      value: '0x0de0b6b3a7640000',
    },],
  })
  console.log({ hash })
}

The Arcana wallet displays a transaction notification for user approval in response to the 'send token' transaction triggered by the app programmatically. The user must approve the send token transaction before the tokens can be successfully sent to the recipient.

Send Transaction
Send Transaction

The wallet displays a 'Preview' button to allow for user confirmation before the send token transaction is executed on the configured blockchain network.

Approve/Reject Send Transaction
Approve/Reject Send Transaction

Receive Tokens

To receive tokens, the app does not need to call any JSON RPC calls. Simply share the user's wallet address or QR code with the sender.

That is all!

The app is all set to programmatically send tokens using the Arcana wallet.

What's Next?

After registering the app, configuring authentication providers, integrating the Arcana Auth SDK with the app and onboarding users, developers can further add code in the app to sign blockchain transactions, send and receive native, ERC20, or custom tokens, and other Web3 wallet operations.

For a complete list of other JSON RPC calls supported by the Arcana wallet, see JSON-RPC Specifications.

See also


Last update: April 12, 2024 by shaloo, shaloo