Post a Message
- TypeScript
- Python
const content = "The resolution is incorrect because...";
// Create message hash
const encoder = new TextEncoder();
const hashBuffer = await crypto.subtle.digest('SHA-256', encoder.encode(content));
const messageHash = Array.from(new Uint8Array(hashBuffer));
const [globalState] = sdk.orica.pda.globalState();
const [position] = sdk.orica.pda.position(marketAddress, wallet.publicKey);
const instruction = await sdk.disputes.buildPostMessage(
wallet.publicKey,
marketAddress,
position,
globalState,
messageHash,
content,
null // No parent message (top-level)
);
const tx = new Transaction().add(instruction);
await sendAndConfirmTransaction(connection, tx, [wallet]);
import hashlib
content = "The resolution is incorrect because..."
ipfs_uri = "ipfs://..." # Store content on IPFS first
# Create message hash
message_hash = hashlib.sha256(content.encode()).digest()
global_state, _ = sdk.orica.pda.global_state()
position, _ = sdk.orica.pda.position(market_address, wallet.pubkey())
instruction = await sdk.disputes.build_post_message(
author=wallet.pubkey(),
market=market_address,
position=position,
global_state=global_state,
message_hash=message_hash,
ipfs_uri=ipfs_uri,
parent_message=None, # No parent (top-level)
)
tx = Transaction()
tx.add(instruction)
await connection.send_transaction(tx, wallet)
Reply to a Message
- TypeScript
- Python
const parentMessagePubkey = new PublicKey("ParentMessage123...");
const instruction = await sdk.disputes.buildPostMessage(
wallet.publicKey,
marketAddress,
position,
globalState,
messageHash,
content,
parentMessagePubkey // Reply to this message
);
parent_message = Pubkey.from_string("ParentMessage123...")
instruction = await sdk.disputes.build_post_message(
author=wallet.pubkey(),
market=market_address,
position=position,
global_state=global_state,
message_hash=message_hash,
ipfs_uri=ipfs_uri,
parent_message=parent_message, # Reply to this message
)
Fetch Dispute Messages
- TypeScript
- Python
const [dispute] = sdk.disputes.pda.dispute(marketAddress);
const messages = await sdk.disputes.fetchDisputeMessages(dispute);
for (const { publicKey, account } of messages) {
console.log("Author:", account.author.toBase58());
console.log("Content:", account.content);
console.log("Timestamp:", new Date(account.timestamp.toNumber() * 1000));
console.log("Author Weight:", account.authorWeight.toString());
console.log("Boost Amount:", account.boostAmount.toString());
console.log("Is Admin:", account.isAdmin);
}
dispute, _ = sdk.disputes.pda.dispute(market_address)
messages = await sdk.disputes.fetch_dispute_messages(dispute)
for address, message in messages:
print(f"Author: {message.author}")
print(f"IPFS URI: {message.ipfs_uri}")
print(f"Timestamp: {message.timestamp}")
print(f"Author Weight: {message.author_weight}")
print(f"Boost Amount: {message.boost_amount}")
print(f"Is Admin: {message.is_admin}")
Message Structure
- TypeScript
- Python
interface DisputeMessage {
dispute: PublicKey;
author: PublicKey;
parentMessage: PublicKey | null;
messageHash: number[];
content: string;
timestamp: BN;
authorWeight: BN;
boostAmount: BN;
isAdmin: boolean;
bump: number;
}
@dataclass
class DisputeMessage:
dispute: Pubkey
author: Pubkey
parent_message: Pubkey | None
message_hash: bytes
ipfs_uri: str
timestamp: int
author_weight: int
boost_amount: int
is_admin: bool
bump: int
Message Requirements
- Must have a position in the market to post
- Author weight reflects position value at time of posting
- Message hash ensures content integrity
- Replies link to parent messages
Next Steps
Boosting
Boost important messages.
Disputes
Back to disputes overview.