Error when trying to delegate

Hello,

I’m not able to delegate my FLOW and keep getting an error, which is:

Error: [Error Code: 1101] error caused by: 1 error occurred: * transaction execute failed: [Error Code: 1101] cadence runtime error: Execution failed: → b04f1e70cff0aef70cac30a05988ef82222d17318947b99e975352ab5e77345a:16:8 | 16 | self.stakingCollectionRef.registerDelegator(nodeID: id, amount: amount) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ error: panic: Cannot register a delegator for a node that is already being delegated to → 8d0e87b65159ae63.FlowStakingCollection:565:20 | 565 | panic(“Cannot register a delegator for a node that is already being delegated to”) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Here is the Code:

import FlowStakingCollection from 0x8d0e87b65159ae63

/// Registers a delegator in the staking collection resource
/// for the specified nodeID and the amount of tokens to commit

transaction(id: String, amount: UFix64) {

let stakingCollectionRef: &FlowStakingCollection.StakingCollection

prepare(account: AuthAccount) {
    self.stakingCollectionRef = account.borrow<&FlowStakingCollection.StakingCollection>(from: FlowStakingCollection.StakingCollectionStoragePath)
        ?? panic("Could not borrow ref to StakingCollection")
}

execute {
    self.stakingCollectionRef.registerDelegator(nodeID: id, amount: amount)      
}

}

And here is the Arguments:

[
{
“type”: “String”,
“value”: “49c9f946170d5fb40c2af953b1534fae771905865b142ab6ac9685b8ba5b51c1”
},
{
“type”: “UFix64”,
“value”: “470.00000000”
}
]

Does anyone know what I have to do here to be able to delegate?

Any help is greatly appreciated!

The error message is saying that you can’t delegate to a node you are already delegating to. The StakingCollection doesn’t allow delegating to the same node twice (instead, you should modify the delegated amount on the existing delegated stake). Perhaps you already ran this transaction to delegate to this node, and the first time it succeeded?

Looking at your account storage, we can see that you have successfully delegated to this node once: flowview | Flow Account Viewer. (click Show Detail and the delegation is there under nodeDelegators)

Hope that helps!