Home / Docs / Contract API

Contract API

Contract 0x4478280Eb1f9477c714d17C380b79511D10Ca88b on GenLayer Studionet (chain 61999). The full ABI is available as chorus.abi.json; source in the GitHub repository.

Conventions

  • Addresses are passed as strings (asker_text, owner_text, reporter_text); the contract parses them and compares lower-case.
  • Amounts are integers in wei (1 GEN = 1018 wei). Large integers in view results may arrive as strings; wrap them in BigInt().
  • Times are Unix seconds, taken from the transaction timestamp.
  • Expected failures revert with a message beginning [EXPECTED]; internal invariant violations use [ERROR].
  • Writes on Studionet need explicit fees. With genlayer-js use estimateTransactionFeesForWrite() and pass fees to writeContract().
const fees = await client.estimateTransactionFeesForWrite({ address, functionName: "commit_answer", args, value: 0n });
const hash = await client.writeContract({ address, functionName: "commit_answer", args, value: 0n, fees });
const receipt = await client.waitForTransactionReceipt({ hash, status: "ACCEPTED" });
⚠️
A transaction can be accepted by consensus yet have the leader’s execution result ERROR. Check the leader receipt, not only the status.

Write methods

deposit_creditpayable

deposit_credit() → int

Adds the attached GEN to your ledger credit and returns the new credit. This is the only way value enters the contract.

Reverts with Deposit must be positive

Send value > 0. Never send a zero deposit.

withdraw_creditwrite

withdraw_credit() → null

Pull payment: transfers your entire available credit to your address in one transfer. Nobody else’s credit is touched.

Reverts with No available credit · Invalid transfer

Withdraw to an externally owned account.

open_questionwrite

open_question(question_id, question_text, reward_wei, stake_wei, min_reporters, max_reporters, commit_by, reveal_by) → string

Opens a question. Validators first run the suitability gate; only a clear verdict with confidence ≥ 70 passes. Then the reward moves from your credit into escrow. Returns the inferred answer shape (name, number, date, yes_no, phrase).

ArgumentTypeNotes
question_idstring1–64 chars: letters, digits, _ . -, starting alphanumeric. Unique per asker.
question_textstring10–400 characters.
reward_weiu256≥ 1014 wei (0.0001 GEN).
stake_weiu256≥ 1014 wei. Per reporter.
min_reporters / max_reportersu163 ≤ min ≤ max ≤ 12.
commit_byunix sCommit deadline: ≥ 2 min and ≤ 30 days after the transaction time.
reveal_byunix sReveal deadline: ≥ 2 min and ≤ 7 days after commit_by.

Reverts with Invalid question id · Duplicate question id · Reward below minimum · Stake below minimum · Invalid reporter limits · Invalid commit deadline · Invalid reveal deadline · Insufficient available credit · Question rejected as {verdict}: {note} · Question screening was inconclusive; rephrase it · Question screening failed; try again · Question screening is unavailable; try again

LLM call inside consensus. Allow a minute or two.

cancel_questionwrite

cancel_question(question_id) → null

Asker only. Cancels while nobody has committed and returns the reward to your credit.

ArgumentTypeNotes
question_idstringYour question id.

Reverts with Question not found · Question cannot be cancelled

commit_answerwrite

commit_answer(asker_text, question_id, commitment_text) → int

Locks the stake from your credit and records your SHA-256 commitment. Returns your report index.

ArgumentTypeNotes
asker_textstringAsker address.
question_idstring
commitment_textstring0x + 64 hex characters.

Reverts with Question not found · Question is not open · Committing is closed · Question is full · Asker cannot answer own question · Reporter already committed · Invalid SHA-256 · Insufficient available credit

Compute the commitment locally; see the Guide.

withdraw_commitwrite

withdraw_commit(asker_text, question_id) → null

Before the commit deadline, withdraws your commitment and refunds the stake to your credit. Your slot stays used.

Reverts with No sealed answer to withdraw · Committing is closed

reveal_answerwrite

reveal_answer(asker_text, question_id, answer_text, salt_text) → null

Reveals the answer. The contract recomputes the commitment and refuses mismatches.

ArgumentTypeNotes
answer_textstring1–240 visible characters; whitespace is collapsed.
salt_textstring16–64 chars from A-Za-z0-9_.~-.

Reverts with Reveal window is not open · No sealed answer to reveal · Invalid salt · Reveal does not match the sealed commitment

Verify locally first to avoid wasting a fee.

adjudicate_questionwrite

adjudicate_question(asker_text, question_id) → null

Asker or a revealed reporter asks validators to group the revealed answers and flag instruction attempts. A strict majority settles the question; an inconclusive attempt is recorded and can be retried.

Reverts with Question is not open · Adjudication window is not open · Too few revealed answers; close the question · Only the asker or a revealed reporter may adjudicate · Adjudication cooldown is active · Adjudication budget exhausted

LLM call inside consensus. A failed or inconclusive attempt still consumes budget.

close_questionwrite

close_question(asker_text, question_id) → null

Anyone. Settles without a ruling once quorum is missing, the deadline has passed or the budget is spent. Honest reporters are refunded; the reward returns to the asker.

Reverts with Reveal window has not closed · Adjudication is still possible

View methods

get_infoview

get_info() → dict

Constants, limits, rules and the list of AI roles.

get_accountingview

get_accounting() → dict

Credits, locked rewards and stakes, liabilities, contract balance, unallocated, shortfall and solvent.

get_available_creditview

get_available_credit(owner_text) → int

Withdrawable credit of an address (wei).

get_recordview

get_record(owner_text) → dict

Counters and totals for an address as asker and reporter, plus majority_rate_bps.

get_question_countview

get_question_count() → int

Total number of questions.

list_questionsview

list_questions(offset, limit) → dict

Newest first. Page size capped at 20. Returns total, offset, entries, has_more.

get_questionview

get_question(asker_text, question_id) → dict

The full question view.

get_question_bundleview

get_question_bundle(asker_text, question_id) → dict

Question, every report and the grouped tally in one read — the whole question page.

get_reportview

get_report(asker_text, question_id, reporter_text) → dict

One reporter’s report.

get_reportersview

get_reporters(asker_text, question_id) → dict

Ordered reporter addresses.

get_rulingview

get_ruling(asker_text, question_id) → dict

The oracle read: status, settlement, resolved, ruling, support, revealed, question.

Data model

Statuses

FieldValues
question.statusopen · resolved · undecided · cancelled
question.settlementmajority_ruling · no_majority · quorum_not_reached · adjudication_deadline_passed · adjudication_budget_exhausted · cancelled_before_any_commit
report.statuscommitted · revealed · withdrawn
report.outcomein_majority · outvoted_stake_forfeited · excluded_instruction_attempt · unrevealed_stake_forfeited · refunded_no_ruling · withdrawn_stake_refunded
question.reasonLast failed adjudication: inconclusive_assessment · consensus_execution_failure · invalid_consensus_result or a referee failure reason.

Question view

question_id, asker, text, shape, gate_note, gate_confidence, reward_wei, stake_wei, min_reporters, max_reporters, report_count, revealed_count, created_at, commit_by, reveal_by, adjudicate_by, status, settlement, ruling, support, adjudication_calls, attempts, retry_at, confidence, rationale, reason, forfeited_wei, reward_returned_wei.

Report view

reporter, index, commitment, status, outcome, answer (empty until revealed), claim, group (0 = ungrouped), committed_at, revealed_at, stake_wei, payout_wei.

Revert reasons

All messages are prefixed [EXPECTED] and surface in the transaction receipt. This site extracts them and shows them in plain text.