Delegations

Delegations

By inherting the delegations standard, your smart contract will be able to execute actions on the behalf of a player.

Players will need to give permission to delegate to your smart contract. You can define the logic which executes when this permission is revoked using canUnregister.

Smart Contract

1. Inherit Delegations

Inherit the ICustomUnregisterDelegation interface in your smart contract.

contract YourContract is ICustomUnregisterDelegation {
 
    function supportsInterface(bytes4 interfaceId) external view override returns (bool) {
        return interfaceId == type(ICustomUnregisterDelegation).interfaceId || interfaceId == type(IERC165).interfaceId;
    }
 
}

2. Define Player Unregister Conditions

Players will use the client to give permission to your smart contract to be able to call actions on behalf of them.

Players can revoke this permission by calling canUnregister. Define any logic that should be executed when this happens, or leave it empty if you don't need to.

In many experiences, you may want to punish a player for revoking delegation before intended. In these cases, you can require a player to submit a stake or a join fee which gets slashed if they prematurely call canUnregister.

contract Game is ICustomUnregisterDelegation {
 
  /**
   * @notice Executes logic before unregistering the user's delegation to this contract.
   * @param delegator The address which has delegated control to this contract.
  */
  function canUnregister(address delegator) external returns (bool);
 
}

3. Call Player Actions On Behalf Of Them

Use callFrom(delegator, systemID, callData) to call an action on behalf of the delegator. For example:

 bytes memory dropCallData = abi.encodeCall(IDropSystem.drop, (inventoryEntityIds, dropCoord));
 
 IWorld(biomeWorldAddress).callFrom(delegatorAddress, DropSystemId, dropCallData);