Mutating and Cloning Accounts
The Luzid mutator
API allows you to mutate accounts by setting their state directly or by
cloning them from a remote cluster.
Mutate Account
In the below example we prepate the mutation we want to apply via the
AccountModification
class. We then call modifyAccount
on the mutator
instance to apply the mutation.
import { AccountModification, LuzidSdk } from '@luzid/sdk'
const luzid = new LuzidSdk()
await luzid.mutator.modifyAccount(
AccountModification.forAddr(accountAddr).setData(
Buffer.from('Hello world! Hola mundo! Hallo Welt!', 'utf8')
)
)
We can modify each property of an account via the relevant set
methods, namely:
Full Example
See the Pen Luzid: Mutate Account by Thorsten Lorenz (@thlorenz) on CodePen.
Clone Account
In order to clone an account into the Luzid validator you provide the remote cluster as well as
the address of the account to clone. Optionally you can provide a commitment
level that
the account must have reached on the remote cluster.
import { Cluster, LuzidSdk } from '@luzid/sdk'
const luzid = new LuzidSdk()
const postAddr = '5ZspQX4nw95meJHpXBF425NytnNTDgtLBBGVDK9EWmRy'
await luzid.mutator.cloneAccount(Cluster.Devnet, postAddr, {
commitment: 'confirmed',
})
Full Example
See the Pen Luzid: Clone Account by Thorsten Lorenz (@thlorenz) on CodePen.
NOTE: the above example demonstrates both cloning a program account and modifying another account.