Allow setting a default dataSuffix when using createWalletClient #4241
-
|
TL;DR: Proposal to add Hey all, the relatively new ERC-8021 spec which the ox library already has support for (thank you) defines a new This Since builders will often just have one builder code they want to attach to all transactions, it would be nice to be able to set that up once, rather than have to add that to every transaction. My recommendation for how to do this is to add a new E.g. import { createWalletClient, custom } from 'viem';
import { mainnet } from 'viem/chains';
import { Attribution } from 'ox/erc8021';
const myDataSuffix = Attribution.toDataSuffix({
codes: ['foobarbaz']
});
type DataSuffixOptionType = `0x${string}` | {
value: `0x${string}`;
required: boolean;
};
const client = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum!),
dataSuffix: {
value: myDataSuffix,
required: false
} satisfies DataSuffixType
});If a user adds this This would apply to both
The value of dataSuffix is typed like this: type DataSuffixOptionType = `0x${string}` | {
value: `0x${string}`;
required: boolean;
};The intended behavior is that if a hex string is used or if required is false, when the Only when required is true should the capability's optional field be false. Alternatives consideredOriginally I was going to suggest adding a E.g. import { createWalletClient, custom } from 'viem';
import { mainnet } from 'viem/chains';
import { Attribution } from 'ox/erc8021';
const myDataSuffix = Attribution.toDataSuffix({
codes: ['foobarbaz']
});
const client = createWalletClient({
chain: mainnet,
transport: custom(window.ethereum!),
defaultCapabilities: {
dataSuffix: {
value: myDataSuffix,
optional: true
}
}
});FWIW, I could be convinced that this is a better interface. SupportI'd be happy to implement this if y'all are open to it, and would likewise be totally okay if someone else did the work. If it's accepted, lmk if you want me to take a stab at it. Wagmi implicationsIf this proposal is accepted, we can talk about extending this functionality to wagmi (likely as a param to |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Implemented in viem@4.25.0 |
Beta Was this translation helpful? Give feedback.
Implemented in viem@4.25.0