So basically while going through the desmjs docs, i found that i have to create subspaceId,
creating subspaceId
useEffect(() => {
const initializeClient = async () => {
const mnemonic = ""
const rpcEndpoint = "http://127.0.0.1:26657";
const gasPrice = GasPrice.fromString("0.025stake");
const signer = await OfflineSignerAdapter.fromMnemonic(SigningMode.DIRECT, mnemonic);
const [account] = await signer.getAccounts();
console.log("Account fetched:", account);
if (!account.address.startsWith("desmos")) {
throw new Error("Invalid account address format");
}
setAccount(account);
const desmosClient = await DesmosClient.connectWithSigner(rpcEndpoint, signer, { gasPrice });
console.log("DesmosClient initialized", desmosClient);
console.log("Account data:", account);
setClient(desmosClient);
// Attempt to create a subspace
const createSubspaceMsg: MsgCreateSubspaceEncodeObject = {
typeUrl: "/desmos.subspaces.v3.MsgCreateSubspace",
value: MsgCreateSubspace.fromPartial({
creator: account.address,
name: "Test Subspace",
description: "This is a test subspace",
}),
};
console.log("Create subspace message:", createSubspaceMsg);
const userAddress = account.address
console.log(userAddress)
try {
const subspaceResult = await desmosClient.signAndBroadcast(userAddress, [createSubspaceMsg], "auto");
console.log("Subspace creation result:", subspaceResult);
// assertIsDeliverTxSuccess(subspaceResult);
// // Extract subspace ID from the raw log events
// const events = subspaceResult.events || [];
// const subspaceIdEvent = events.find(
// (event) =>
// event.type === "created_subspace" &&
// event.attributes.some((attr) => attr.key === "subspace_id")
// );
// if (subspaceIdEvent) {
// const subspaceIdAttr = subspaceIdEvent.attributes.find((attr) => attr.key === "subspace_id");
// if (subspaceIdAttr) {
// setSubspaceId(Long.fromString(subspaceIdAttr.value)); // Convert string to Long type
// console.log(`Subspace ID: ${subspaceIdAttr.value}`);
// } else {
// console.error("Subspace ID attribute not found in event");
// }
// } else {
// console.error("Created subspace event not found");
// }
} catch (error) {
console.error("Failed to create subspace:", error);
}
};
initializeClient();
}, []);
the error i have been getting
VM41549 page.tsx:206 Failed to create subspace: Error: Query failed with (6): rpc error: code = Unknown desc = invalid owner address: invalid address [desmos-labs/desmos/v7/x/subspaces/types/msgs.go:95] With gas wanted: '0' and gas used: '1168' : unknown request
at QueryClient.queryAbci (queryclient.js:118:19)
at async Object.request (utils.js:35:30)
at async Object.simulate (queries.js:50:34)
at async DesmosClient.simulate (signingcosmwasmclient.js:90:29)
at async DesmosClient.signAndBroadcast (desmosclient.js:74:35)
at async initializeClient (VM41549 page.tsx:182:40)
The function below is for creating post
const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();
// Ensure client and subspaceId are ready
if (!client || !subspaceId) {
alert("Client not initialized or subspace not selected");
return;
}
console.log({client, subspaceId})
try {
const msg: MsgCreatePostEncodeObject = {
typeUrl: "/desmos.posts.v3.MsgCreatePost",
value: MsgCreatePost.fromPartial({
subspaceId, // Use state variable here
sectionId: 0,
text: postText,
author: account?.address,
replySettings: ReplySetting.REPLY_SETTING_EVERYONE,
})
};
const result = await client.signAndBroadcast(account?.address || "", [msg], "auto");
assertIsDeliverTxSuccess(result);
alert("Post created successfully!");
} catch (error) {
console.error("Failed to create post:", error);
alert("Failed to create post. See console for details.");
}
};
So basically while going through the desmjs docs, i found that i have to create subspaceId,
creating subspaceId
useEffect(() => {
const initializeClient = async () => {
const mnemonic = ""
const rpcEndpoint = "http://127.0.0.1:26657";
const gasPrice = GasPrice.fromString("0.025stake");
const signer = await OfflineSignerAdapter.fromMnemonic(SigningMode.DIRECT, mnemonic);
const [account] = await signer.getAccounts();
}, []);
the error i have been getting
VM41549 page.tsx:206 Failed to create subspace: Error: Query failed with (6): rpc error: code = Unknown desc = invalid owner address: invalid address [desmos-labs/desmos/v7/x/subspaces/types/msgs.go:95] With gas wanted: '0' and gas used: '1168' : unknown request
at QueryClient.queryAbci (queryclient.js:118:19)
at async Object.request (utils.js:35:30)
at async Object.simulate (queries.js:50:34)
at async DesmosClient.simulate (signingcosmwasmclient.js:90:29)
at async DesmosClient.signAndBroadcast (desmosclient.js:74:35)
at async initializeClient (VM41549 page.tsx:182:40)
The function below is for creating post
const handleSubmit = async (event: React.FormEvent) => {
event.preventDefault();
};