Skip to content

Commit

Permalink
docs: clarify callFrom changelog (#2579)
Browse files Browse the repository at this point in the history
  • Loading branch information
holic authored Apr 1, 2024
1 parent 3b845d6 commit 090a099
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions .changeset/nervous-nails-notice.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,36 @@
"@latticexyz/world": patch
---

This is an internal feature and is not ready for stable consumption yet.
Added a viem client decorator for account delegation. By extending viem clients with this function after delegation, the delegation is automatically applied to World contract writes. This means that these writes are made on behalf of the delegator. Internally, it transforms the write arguments to use `callFrom`.

Added viem custom client actions for delegation. By extending viem clients with this function after delegation, the delegation is automatically applied to World contract writes. This means that these writes are made on behalf of the delegator. Internally, it transforms the write arguments to use `callFrom`.
This is an internal feature and is not ready for stable consumption yet, so it's not yet exported. Its API may change.

Usage example:
When using with a viem public client, system function selectors will be fetched from the world:

```ts
walletClient.extend(
callFrom({
worldAddress,
delegatorAddress,
publicClient, // Instead of using `publicClient`, you can pass a mapping function as shown below. This allows you to use your client store and avoid read requests.
// worldFunctionToSystemFunction: async (worldFunctionSelector) => {
// const systemFunction = useStore
// .getState()
// .getValue(tables.FunctionSelectors, { worldFunctionSelector })!;
// return { systemId: systemFunction.systemId, systemFunctionSelector: systemFunction.systemFunctionSelector };
// },
publicClient,
}),
);
```

Alternatively, a `worldFunctionToSystemFunction` handler can be passed in that will translate between world function selectors and system function selectors for cases where you want to provide your own behavior or use data already cached in e.g. Zustand or RECS.

```ts
walletClient.extend(
callFrom({
worldAddress,
delegatorAddress,
worldFunctionToSystemFunction: async (worldFunctionSelector) => {
const systemFunction = useStore.getState().getValue(tables.FunctionSelectors, { worldFunctionSelector })!;
return {
systemId: systemFunction.systemId,
systemFunctionSelector: systemFunction.systemFunctionSelector,
};
},
}),
);
```

0 comments on commit 090a099

Please sign in to comment.