import { KeyType, PublicKey } from '@near-js/crypto'
import { JsonRpcProvider } from '@near-js/providers'
import { actionCreators, createTransaction } from '@near-js/transactions'
import { baseDecode } from '@near-js/utils'
const walletId = 'wa-172um-hgi5f-xxxxxxxxxxxxxxxx'
const wallet = await dfnsClient.wallets.getWallet({ walletId })
const provider = new JsonRpcProvider({url: process.env.NEAR_NODE_URL!})
const publicKey = new PublicKey({
keyType: KeyType.ED25519,
data: Buffer.from(wallet.address!, 'hex'),
})
const accessKey = await provider.viewAccessKey(wallet.address!, publicKey)
const nonce = accessKey.nonce++
const recentBlockHash = baseDecode(accessKey.block_hash)
const transaction = createTransaction(
address,
publicKey,
'f04bc9ba7bc685d12cf87731cc4820c13920723b6a7736cf25b6bc898ccdc3a8',
nonce,
[actionCreators.transfer(1n)],
recentBlockHash
)
const res = await dfnsClient.wallets.generateSignature({
walletId,
body: {
kind: 'Transaction',
transaction: `0x${Buffer.from(transaction.encode()).toString('hex')}`,
},
})