Skip to content

Contract reference

Every method of the deployed Primacy contract, with arguments, results and the errors it can raise. Addresses are text, so any case works. Amounts are in wei: 1 GEN is 1018 wei.

Calling the contract

The website uses genlayer-js. Reads need no wallet. Writes go through any EIP-1193 provider, including the one an EIP-6963 wallet announces.

import { createClient } from "genlayer-js";
import { studionet } from "genlayer-js/chains";

const CONTRACT = "0xf49Fca785788a2a3881c593F33B2E20113FD99e1";

// Read, no wallet needed
const reader = createClient({ chain: studionet });
const bounty = await reader.readContract({
  address: CONTRACT, functionName: "get_bounty",
  args: ["0x174fbcdecffc4ada6bd69470fcea8dce760eac3e", "MAIN"],
});

// Write through a wallet provider found with EIP-6963
const client = createClient({ chain: studionet, account: accountAddress, provider: walletProvider });
const hash = await client.writeContract({
  address: CONTRACT, functionName: "deposit_credit", args: [], value: 10n ** 17n,
});
Always read the result, not just the status.

A transaction can reach consensus while the contract rejected the call. After the status becomes ACCEPTED, read the leader receipt's execution result. The website does this for every write and shows the contract's own message.

If Studionet has fees enabled (sim_getFeeConfig returns enabled), estimate them with client.estimateTransactionFees() and pass them as fees. The website does this automatically.

Numbers above 253 come back from readContract as strings, so convert amounts with BigInt(value).

Data shapes

Bounty record

NameTypeDescription
keystrLowercase sponsor:id.
bounty_idstrThe id.
sponsorstrSponsor address, lowercase.
scopestrThe scope text.
reward_weiintReward per slot.
bond_weiintBond per finding.
slotsintTotal slots.
headsintSlots already paid.
commit_byintCommit deadline, unix time.
reveal_windowintSeconds allowed to reveal after each commit.
review_byintReview deadline, unix time.
created_at / closed_atintUnix times. closed_at is 0 while open.
escrowintReward still held for unpaid slots.
finding_countintFindings committed so far.
cursorintIndex of the earliest undecided finding.
statusstropen, closed or cancelled.
close_reasonstrall_slots_filled, review_deadline, commit_window_ended or cancelled_before_any_commit.

Finding record

NameTypeDescription
indexintQueue position.
hunterstrHunter address, lowercase.
commitmentstrThe committed fingerprint.
title / bodystrEmpty until revealed.
statusstrcommitted, revealed, distinct, duplicate, invalid, unresolved, void or late.
committed_at / revealed_at / decided_atintUnix times, 0 when not reached.
reveal_byintReveal deadline.
bond_wei / bond_stateint / strBond amount still held, and locked, refunded or forfeited_to_sponsor.
reward_weiintReward paid, 0 unless distinct.
duplicate_ofintIndex of the accepted finding it duplicates, or -1.
in_scope / actionablestrThe validators' answers: yes, no, unclear, or empty.
confidence / rationaleint / strValidator confidence 0 to 100 and a short explanation.
reasonstrMachine reason such as not_revealed_in_time or inconclusive_assessment.
attempts / failuresintInconclusive answers and operational failures so far.
retry_atintEarliest time the next review may run.

Write methods

deposit_creditwrite payableAnyone, sends GEN
deposit_credit() -> int

Credits the attached GEN to the actual sender. Send the value with the call, never as a plain transfer.

No arguments.

Returns. The amount credited, in wei.

Rejected with.

  • Deposit must be positive
withdraw_creditwriteAnyone with credit
withdraw_credit() -> int

Sends the caller's whole available credit to the caller. It is the only method that emits a transfer. Locked funds are not affected.

No arguments.

Returns. The amount sent, in wei.

Rejected with.

  • No available credit
  • This method does not accept value
create_bountywriteSponsor
create_bounty(bounty_id, scope_text, reward_wei, slots, bond_wei, commit_by, reveal_window, review_by) -> str

Locks reward × slots from the sponsor's credit into escrow. The id is unique per sponsor, so two sponsors can use the same id.

NameTypeDescription
bounty_idstr1 to 64 characters, [A-Za-z0-9][A-Za-z0-9_.-]*.
scope_textstr20 to 800 characters after whitespace is collapsed.
reward_weiu256Reward per slot, 1014 to 1027.
slotsu161 to 8.
bond_weiu256From 1012 up to the reward.
commit_byu256Unix time. Between now + 10 minutes and now + 60 days.
reveal_windowu256Seconds, 300 to 604800, counted from each commit.
review_byu256Unix time. Between commit_by + reveal_window + 1 day and + 90 days.

Returns. The bounty key, sponsor:id in lowercase.

Rejected with.

  • Invalid bounty id
  • Invalid scope
  • Invalid reward
  • Invalid slot count
  • Invalid bond
  • Invalid reveal window
  • Invalid commit deadline
  • Invalid review deadline
  • Duplicate bounty id
  • Insufficient available credit
cancel_bountywriteSponsor only
cancel_bounty(bounty_id) -> None

Possible only while the bounty is open and nobody has committed. Returns the whole escrow to the sponsor's credit.

NameTypeDescription
bounty_idstrThe sponsor's bounty id.

Returns. Nothing.

Rejected with.

  • Bounty not found
  • Bounty cannot be cancelled
close_bountywriteAnyone
close_bounty(sponsor_text, bounty_id) -> None

Allowed after the review deadline, or once the commit deadline has passed and no finding is pending. Settles leftover bonds, returns unused escrow to the sponsor, and marks the bounty closed.

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.

Returns. Nothing.

Rejected with.

  • Bounty is not open
  • Bounty cannot be closed yet
commit_findingwriteAny hunter except the sponsor
commit_finding(sponsor_text, bounty_id, commitment_text) -> int

Locks the bond from the hunter's credit, appends the finding to the queue, and sets its reveal deadline to now + the reveal window.

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.
commitment_textstr0x plus 64 hex characters, the SHA-256 fingerprint.

Returns. The finding's index in the queue.

Rejected with.

  • Commit window is closed
  • Sponsor cannot submit findings
  • All reward slots are filled
  • Finding limit reached
  • Per-hunter finding limit reached
  • Invalid commitment
  • Insufficient available credit
reveal_findingwriteThe committing hunter
reveal_finding(sponsor_text, bounty_id, index, title, body, salt) -> None

Recomputes the fingerprint from the revealed fields. If it matches, the text is stored and the finding becomes revealed. Text is validated, never trimmed or rewritten.

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.
indexu16Position in the queue, starting at 0.
titlestr1 to 120 characters, one line, exact.
bodystr1 to 1200 characters, exact.
saltstr16 to 64 characters from A-Za-z0-9_-.

Returns. Nothing.

Rejected with.

  • Only the committing hunter may reveal
  • Finding is not awaiting reveal
  • Reveal window elapsed
  • Invalid title
  • Invalid body
  • Invalid salt
  • Reveal does not match commitment
void_unrevealedwriteAnyone
void_unrevealed(sponsor_text, bounty_id, index) -> None

Marks a commitment whose reveal window has passed as void, sends its bond to the sponsor, and lets the queue advance.

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.
indexu16Position in the queue, starting at 0.

Returns. Nothing.

Rejected with.

  • Finding cannot be voided
adjudicatewriteAnyone
adjudicate(sponsor_text, bounty_id) -> str

Decides the earliest undecided finding. Runs the copy guard, then asks validators, then applies the decision table. This is the only method that calls a language model, so it takes longer than the others.

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.

Returns. The earliest finding's status after the call: distinct, duplicate, invalid, unresolved, or still revealed after an inconclusive answer.

Rejected with.

  • Bounty is not open
  • Review window elapsed
  • No finding awaits adjudication
  • Earliest finding awaits reveal or voiding
  • Adjudication cooldown is active

View methods

get_creditviewAnyone
get_credit(owner_text) -> int

NameTypeDescription
owner_textstrAddress of the account.

Returns. Available credit in wei.

Rejected with.

  • Invalid credit owner
get_accountingviewAnyone
get_accounting() -> dict

Compares what the contract owes with what it holds. A positive unallocated_balance means GEN arrived by plain transfer.

No arguments.

Returns. total_credits, total_locked, accounted_liabilities, contract_balance, unallocated_balance, balance_shortfall and solvent.

get_bountyviewAnyone
get_bounty(sponsor_text, bounty_id) -> dict

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.

Returns. A bounty record, see the table below.

Rejected with.

  • Bounty not found
get_findingviewAnyone
get_finding(sponsor_text, bounty_id, index) -> dict

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.
indexu16Position in the queue, starting at 0.

Returns. A finding record, see the table below.

Rejected with.

  • Bounty not found
  • Finding not found
get_findingsviewAnyone
get_findings(sponsor_text, bounty_id) -> list

NameTypeDescription
sponsor_textstrSponsor address, any case.
bounty_idstrThe sponsor's bounty id.

Returns. Every finding of the bounty in queue order.

Rejected with.

  • Bounty not found
get_infoviewAnyone
get_info() -> dict

Useful for checking that a deployment is what you expect.

No arguments.

Returns. Name, version, commitment domain, every limit in this reference, and short descriptions of the priority rule, settlement model and bond policy.