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
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
//clientId : Arcana Unique App Identifier via Dashboard
const clientId = 'xar_test_445007f942f9Ba718953094BbeeeeeB9484cAfd2'
const auth = new AuthProvider(`${clientId}`, { //required
network: 'testnet', //defaults to 'testnet'
position: 'left', //defaults to right
theme: 'light', //defaults to dark
alwaysVisible: false, //defaults to true, wallet always visible
chainConfig: {
chainId: CHAIN.POLYGON_MAINNET, //defaults to CHAIN.ETHEREUM_MAINNET
rpcUrl: 'https://polygon-rpc.com', //defaults to 'https://rpc.ankr.com/eth'
},
})
try {
await auth.init()
} catch (e) {
// Handle exception case
}
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
- Arcana wallet capabilities
- Configure Arcana wallet Visibility
- Send transaction
- Watch Token Assets
- Check account balance
- Auth SDK Reference Guide