This section guides you through the process of obtaining an access token, using it to get a signed transaction from the Vault, and broadcasting that transaction to the blockchain with viem.
This page requires Entity and Policy stores configured. If you don't have them, see theQuick start section first.
import { Action, getAddress, resourceId, toHex } from'@narval/armory-sdk'import { SignTransaction } from'@narval/policy-engine-shared'import { v4 as uuid } from'uuid'import { createPublicClient, http } from'viem'import { sepolia } from'viem/chains'construn=async () => {// ...constsignTransaction:SignTransaction= { action:Action.SIGN_TRANSACTION, nonce:uuid(), resourceId:resourceId(accounts[0].address), transactionRequest: { from:getAddress(accounts[0].address), to:'0x7099797...0d17dc79c8', chainId:137, value:toHex(1000000000000000000n), nonce:192, type:'0', gas:21000n, gasPrice:1000000000n } }constsignTransactionAccessToken=awaitauthClient.requestAccessToken(signTransaction)const { signature } =awaitvaultClient.sign({ data: signTransaction,// Authorized request accessToken: signTransactionAccessToken // Token authorizing the request })console.log('Signature:', signature)constclient=createPublicClient({ chain: sepolia, transport:http() })// IMPORTANT: This call will fail because the `wallet` does not have sufficient// funds.consthash=awaitclient.sendRawTransaction({ serializedTransaction: signature })console.log('Tx hash:', hash)}run()