Getting error in sending transaction

import React, {useState} from “react”

import * as fcl from “@onflow/fcl”

import styled from ‘styled-components’

import * as t from “@onflow/types”

import * as sdk from “@onflow/sdk”

const simpleTransaction = fcl.cdc`

import HelloWorld from 0x4fc019cea9fc4817

transaction {

    prepare(account: AuthAccount) {

      let capability = account.link<&HelloWorld.HelloAsset>(/public/Hello, target: /storage/Hello)

      let helloReference = capability!.borrow()

        ?? panic("Could not borrow a reference to the hello capability")

      log(helloReference.hello())

    }

  }

`

const SendTransaction = () => {

const [status, setStatus] = useState(“Not started”)

const [transaction, setTransaction] = useState(null)

const sendTransaction = async (event) => {

event.preventDefault()



setStatus("Resolving...")

const blockResponse = await fcl.send([

  fcl.getLatestBlock(),

])

const block = await fcl.decode(blockResponse)



try {

  const tx = await fcl.send([

    fcl.transaction(simpleTransaction),

    fcl.proposer(fcl.currentUser().authorization),

    fcl.payer(fcl.currentUser().authorization),

    fcl.ref(block.id),

  ])

  const { transactionId } = tx

  setStatus(`Transaction (${transactionId}) sent, waiting for confirmation`)

  const unsub = fcl

    .tx(transactionId)

    .subscribe(transaction => {

      setTransaction(transaction)

      if (fcl.tx.isSealed(transaction)) {

        setStatus(`Transaction (${transactionId}) is Sealed`)

        unsub()

      }

    })

} catch (error) {

  console.error(error)

  setStatus("Transaction failed")

}

}

return (

<Card>

  <Header>send transaction</Header>

  <Code>{simpleTransaction}</Code>

  <button onClick={sendTransaction}>

    Send

  </button>

  <Code>Status: {status}</Code>

  {transaction && <Code>{JSON.stringify(transaction, null, 2)}</Code>}

</Card>

)

}

export default SendTransaction

but getting error

[Error Code: 1101] cadence runtime error Execution failed:\nerror: authorizer count mismatch for transaction: expected 1, got 0\n–> d318adf48d25986c4d63fea82ca201236256dcaf332459684c1379724bf3ea90\n",

can anybody help me

Your cadence prepare statement specifies an auth account, but when you are building the transaction you arent supplying an authorizer.

transaction {
  prepare(account: AuthAccount) {
     //.     ^---- Your transaction needs to deal with this.
  }
}

You can add an authorizer with the fcl.authorizations builder. It expects an array of Authorization Functions, the order of the array lines up with the order of AuthAccounts passed into the prepare statement.

You need to add

  fcl.send([
    /// other stuff
      fcl.proposer(fcl.currentUser().authorization),
      fcl.payer(fcl.currentUser().authorization),
      fcl.authorizations([               // add this
        fcl.currentUser().authorization  // add this
      ]),                                // add this
    /// other stuff
  ])
1 Like

Yup it worked Thank you for helping out