Skip to content

Send Tokens

Arcana wallet is an embedded Web3 wallet available to all the dApps that integrate with the Arcana Auth SDK.

In this guide, you will learn how dApps can use the JSON RPC calls supported by the Arcana wallet to allow users to send tokens.

To receive tokens using the Arcana wallet, the dApp user can choose to copy their wallet account address or get a QR code for their account. The account address or QR code can be shared with the sender in order to receive tokens.

Prerequisites

Register and configure your application using the Arcana Developer Dashboard. Next, install the @arcana/auth package. Integrate the Auth SDK with your dApp. For details, see Arcana Auth Quick Start Guide.

const { AuthProvider } = window.arcana.auth // From CDN
//or
import { AuthProvider, CHAIN } from '@arcana/auth' //From npm
const appAddress = '445007f942f9Ba718953094BbeeeeeB9484cAfd2' // App Address Example

const auth = new AuthProvider(`${appAddress}`, {
  position: 'left', // defaults to right
  theme: 'light', // defaults to dark
  alwaysVisible: false, // defaults to true which is Full UI mode
  chainConfig: {
    chainId: CHAIN.POLYGON_MAINNET,
    rpcUrl: '',
  },
})
try {
  await auth.init()
} catch (e) {
  // Handle exception case
}

Make sure you have already initialized the wallet before invoking any JSON RPC calls for sending tokens using the Arcana wallet.

// 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 application is registered, configured and integrated with the Auth SDK, you can wire the user action in your dApp for sending tokens by implementing a '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 springs into action when a user initiates a 'send token' transaction through the dApp. The following figure shows the Arcana wallet screen that shows up allowing users to input the token amount, gas, and recipient details for sending tokens.

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

Receive Tokens

To receive tokens, the dApp does not need to call any JSON RPC calls.

Visit the 'home' screen of the Arcana wallet by clicking on the 'home' icon on the bottom left. Use the 'Receive' button to view the QR code or copy the receiver's account address.

Share this QR code or the account address with the sender. The sender can use the Arcana wallet or any other third-party Web3 wallet to send tokens. The dApp user can view the tokens once they are received in the wallet home screen. Use the 'Refresh Balance' button to check the balance. For more details on wallet usage, see Arcana wallet User Guide.

That is all! You are all set to send and receive tokens using the Arcana wallet.

What's Next?

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

See also


Last update: January 11, 2023 by shaloo