Closed jacob-tucker closed 4 months ago
Hi @jacob-tucker ,
Thank you for raising the issue you've encountered. Upon investigation, it seems that the mismatch lies between the account object type obtained from window.ethereum.request
and the LocalAccount
object that the SDK expects.
The account details we retrieve:
const [account]: [Address] = await window.ethereum.request({
method: "eth_requestAccounts",
});
The account is the wallet address as a string, which differs from the LocalAccount
object required by the SDK for operations like signTypedData
. The SDK needs a LocalAccount
for signature-based
functions, particularly when dealing with metadata
registration.
To solve this, the wagmi
library is our recommended tool. It provides user-friendly hooks for Ethereum wallet interactions, ensuring proper account handling. MetaMask also recommends the use of wagmi
.
You can employ wagmi to properly interface with the SDK as demonstrated below:
const { data: wallet } = useWalletClient();
// Instantiate a new client for the SDK
const client = StoryClient.newClient({
chainId: "sepolia",
account: wallet!.account,
transport: http(RPC),
});
// Utilize the signTypedData method on the account object
wallet?.account.signTypedData(/* ... */);
Remember that wagmi Core acts as a seamless interface on top of viem
, facilitating wallet management and related operations.
I trust this clarifies the required approach and aids in the seamless integration of the account with the SDK. Should you need additional assistance or encounter more issues, please don't hesitate to get in touch.
Warm regards,
Bonnie
Hi @bonnie57 , can you clarify what the purpose of signTypedData
is? Where do I call that function?
I have setup the wagmi
library in my DApp and configured the StoryClient
like so:
const config: StoryConfig = {
account: wallet?.account as Account,
transport: custom(wallet.transport),
chainId: "sepolia",
};
const client = StoryClient.newClient(config);
However when I use this client to register IP Asset, I still get the same error.
Hi @jacob-tucker,
I noticed you're encountering issues with the signTypedData
method used for signatures, which is required by the spg
method. If you don't plan to use the spg method, you can opt to skip passing the metadata
information in the register
method.
Regarding the error, it seems that the issue may be due to version discrepancies. If you are using the latest version of the wagmi library, the wallet.account object may not have a signTypedData method. To test the signature feature, you can use the following example:
const sepolia: SupportedChainIds = "sepolia";
const config = {
chainId: sepolia,
transport: http("http://localhost:8545"),
account: privateKeyToAccount(privateKey),
};
setClient(StoryClient.newClient(config));
console.log(walletClient.account.signTypedData);
const client = StoryClient.newClient(config);
However, passing the private key
directly is not user-friendly. Therefore, I will consider changing how the signTypedData method is called to improve the user experience.
Thank you for your understanding and cooperation!
Hi @bonnie57 , thanks for your response! I believe the issue is that in the latest version of wagmi, signTypedData
exists on walletClient
like so: walletClient.signTypedData
. Maybe we have to update SDK so that it recognizes this since it does not exist on the walletClient.account
Hi @jacob-tucker,
Thank you for your response. I really appreciate your input. Your suggestion makes a lot of sense. I'm considering using walletClient.signTypedData
to obtain the signature as it seems to be compatible with both viem
and wagmi
. However, there are some special cases, like AA
, that the SDK needs to accommodate. This is why we've set walletClient to SimpleWalletClient
which not have signTypedData method, rather than WalletClient.
export type SimpleWalletClient<
TChain extends Chain | undefined = Chain | undefined,
TAccount extends Account | undefined = Account | undefined,
> = {
account?: TAccount;
writeContract: <
const abi extends Abi | readonly unknown[],
functionName extends ContractFunctionName<abi, "payable" | "nonpayable">,
args extends ContractFunctionArgs<abi, "payable" | "nonpayable", functionName>,
TChainOverride extends Chain | undefined = undefined,
>(
args: WriteContractParameters<abi, functionName, args, TChain, TAccount, TChainOverride>,
) => Promise<WriteContractReturnType>;
};
Regarding the account, we're encountering similar compatibility issues. In the SDK, the account type is defined asAccount | Address
to ensure compatibility.
export type Account<TAddress extends Address = Address> = OneOf<
JsonRpcAccount<TAddress> | LocalAccount<string, TAddress>
>
If the account type is LocalAccount
, then account.signTypedData
can be called. Otherwise, the method cannot be invoked, resulting in an error, as you've noticed. However, obtaining LocalAccount in wagmi
seems to be challenging. We're looking into ways to improve this.
In summary, it seems there's a trade-off between compatibility and user-friendliness. I'll discuss this further with @edisonz0718 and get back to you with any updates. Thank you for your patience
Hello @jacob-tucker,
In the latest release, version 1.0.0-rc.14 of the SDK, you now have the ability to pass wallet:WalletClient
to complete the signature. However, if you're using a wallet via AA, you might encounter errors similar to those you've experienced before.
We hope you enjoy the new version! If you have any questions or need assistance, please feel free to reach out to me.
Amazing Bonnie! It worked perfectly 👏
Describe the bug If I use Metamask to sign transaction, and I add metadata to the
.register
function, I get the following error:Error: Failed to register IP: The account does not support signTypedData, Please use a local account.
If I pass no metadata, it works. Other functions also work with metamask.