Skip to main content

mutate

A transaction execution function that allows you to submit Cadence transactions to the Flow blockchain to mutate on-chain state. This function handles the complete transaction lifecycle including building, signing, and sending transactions to Flow. It provides a high-level interface that abstracts the complexity of transaction construction while offering flexibility for advanced use cases.

The mutate function automatically handles authorization using the current authenticated user by default, but allows for custom authorization functions to be specified for different transaction roles (proposer, payer, authorizer). It supports both simple single-party transactions and complex multi-party transactions with different signatories.

This function integrates with FCL's address replacement system, allowing you to use placeholder addresses in your Cadence code that are replaced with actual addresses at execution time. It also supports Interaction Templates for standardized transaction execution patterns.

The mutate function accepts a configuration object with the following structure:


_10
{
_10
cadence?: string, // The Cadence transaction code to execute (required if template not provided)
_10
args?: Function, // Function that returns an array of arguments for the transaction
_10
template?: any, // Interaction Template object or URL for standardized transactions
_10
limit?: number, // Compute (gas) limit for the transaction execution
_10
authz?: AccountAuthorization, // Authorization function for all signatory roles (proposer, payer, authorizer)
_10
proposer?: AccountAuthorization, // Specific authorization function for the proposer role
_10
payer?: AccountAuthorization, // Specific authorization function for the payer role
_10
authorizations?: AccountAuthorization[] // Array of authorization functions for authorizer roles
_10
}

Import

You can import the entire package and access the function:


_10
import * as fcl from "@onflow/fcl"
_10
_10
fcl.mutate(opts)

Or import directly the specific function:


_10
import { mutate } from "@onflow/fcl"
_10
_10
mutate(opts)

Usage


_30
// Basic transaction submission
_30
import * as fcl from "@onflow/fcl"
_30
_30
// Configure FCL first
_30
fcl.config({
_30
"accessNode.api": "https://rest-testnet.onflow.org",
_30
"discovery.wallet": "https://fcl-discovery.onflow.org/testnet/authn",
_30
"flow.network": "testnet"
_30
})
_30
_30
// Authenticate user
_30
await fcl.authenticate()
_30
_30
// Submit a basic transaction
_30
const txId = await fcl.mutate({
_30
cadence: `
_30
transaction(message: String) {
_30
prepare(account: AuthAccount) {
_30
log("Transaction executed by: ".concat(account.address.toString()))
_30
log("Message: ".concat(message))
_30
}
_30
}
_30
`,
_30
args: (arg, t) => [
_30
arg("Hello Flow!", t.String)
_30
],
_30
limit: 50
_30
})
_30
_30
console.log("Transaction submitted:", txId)

Parameters

opts

  • Type: any
  • Description: Transaction configuration options

Returns


_10
(opts?: MutateOptions) => Promise<string>

Promise that resolves to the transaction ID (txId) when the transaction is submitted


Rate this page