Skip to main content

Sign Transactions

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 a dApp can add functionality to allow users to sign blockchain transactions by using the JSON RPC calls supported by Arcana wallet.

Prerequisites

  • Install the @arcana/auth package. Integrate the Auth SDK with your dApp. For details, see Arcana Auth Quick Start Guide.

    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
    }

    provider = auth.getProvider()
    // or
    provider = window.ethereum
  • Make sure you have already initialized the wallet before invoking any JSON RPC call to sign a transaction using 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 })
    })
    }

Sign Transaction

async function signTransaction() {

const { sig } = await provider.request({
method: 'eth_signTransaction',
params: [
{
from, // sender account address
gasPrice: 0,
to: '0xE28F01Cf69f27Ee17e552bFDFB7ff301ca07e780', // receiver account address
value: '0x0de0b6b3a7640000',
},
],
})
console.log({ sig })
}

The following figure shows how Arcana wallet displays the details of a blockchain sign transaction and asks the user to approve or reject it:

That is all! 🎉 You are all set to allow dApp users to sign blockchain transactions.

What's Next?

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

See also