Skip to main content

getMutate

Legacy factory function that creates a mutate function using global FCL context. This function provides backward compatibility for code that was written before the introduction of dependency injection patterns in FCL. It creates a mutate function by combining a partial global context with a provided current user service.

This function is considered legacy and should be used primarily for backward compatibility. New code should prefer using the createMutate function with a complete FCL context for better testability and dependency management.

The function creates a partial context using global configuration and SDK methods, then combines it with the provided current user service to create a fully functional mutate function.

Import

You can import the entire package and access the function:


_10
import * as fcl from "@onflow/fcl-core"
_10
_10
fcl.getMutate(currentUserOrConfig)

Or import directly the specific function:


_10
import { getMutate } from "@onflow/fcl-core"
_10
_10
getMutate(currentUserOrConfig)

Usage


_18
// Legacy usage with global context
_18
import { getMutate } from "@onflow/fcl-core"
_18
import { getCurrentUser } from "@onflow/fcl-core"
_18
_18
// Get the current user service
_18
const currentUser = getCurrentUser({ platform: "web" })
_18
_18
// Create mutate function using legacy pattern
_18
const mutate = getMutate(currentUser)
_18
_18
// Use the mutate function
_18
const txId = await mutate({
_18
cadence: `
_18
transaction {
_18
execute { log("Hello, Flow!") }
_18
}
_18
`
_18
})

Parameters

currentUserOrConfig

  • Type:

_10
export interface CurrentUserService extends CurrentUserServiceApi {
_10
(): CurrentUserServiceApi
_10
}

  • Description: The current user service instance that provides authentication and authorization capabilities. This service must implement the CurrentUserService interface and provide methods for user authentication, authorization, and session management.

Returns

Promise<string>

A mutate function that can submit transactions to the Flow blockchain. The returned function accepts the same options as the standard mutate function:

  • cadence: The Cadence transaction code to execute
  • args: Function that returns transaction arguments
  • template: Interaction template for standardized transactions
  • limit: Compute limit for the transaction
  • authz: Authorization function for all roles
  • proposer: Specific authorization for proposer role
  • payer: Specific authorization for payer role
  • authorizations: Array of authorization functions for authorizer roles

Rate this page