Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

How to use Mandate

Every command is for the onyx-1 test network and uses test GNOT. Replace the words in capitals. Amounts are in ugnot (1 GNOT = 1,000,000 ugnot); periods and times are in seconds and unix seconds.

For creators

  1. Publish a plan with your own key: a title (one line, at most 80 characters, no invisible formatting characters: direction controls and zero-width characters, the joiner included, are refused, so emoji joined into one, such as families, cannot be used), the amount (at least 0.1 GNOT) and the period (60 seconds to 30 days). Plans cannot be changed.
gnokey maketx call -pkgpath gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate -func Offer -args "TITLE" -args 1000000 -args 604800 -gas-fee 100000ugnot -gas-wanted 60000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 YOUR_KEY
  1. Make a separate key for collecting (gnokey add COLLECTOR_KEY) and publish its public key (the gpub1... value gnokey list shows), signed with your own key. Never send coins to the collector key's address, not even for fees (the supporter pays every fee): an address that has received coins is an account, and the chain refuses to create a session for it, so nobody new could subscribe. Anyone can do this to a published key with a 1 ugnot send, and a realm can even make the address an account that holds nothing. In most cases the plan page then says so; in every case supporters get the chain error session key address collides with existing account when they create the session, and the collector script warns. Then the key can no longer be used for new sessions: make a new key and publish it (this command again). New supporters then use the new key, and existing mandates keep being collected with the old one: run one collector per key. Subscribe accepts any session key you hand out, so you can also give supporters a fresh key privately:
gnokey maketx call -pkgpath gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate -func SetCollectorKey -args GPUB_OF_COLLECTOR_KEY -gas-fee 100000ugnot -gas-wanted 60000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 YOUR_KEY
  1. Collect each payment when it is due, signed with the collector key on behalf of the supporter. Only the exact price is accepted, at most once per period. The fee counts against the supporter's fee allowance, so keep it small. The command below uses today's minimum fee on onyx-1 (1 ugnot per 1,000 gas); when the chain raises its gas price, raise -gas-fee with it (gnokey query auth/gasprice), within the allowance. The collector script does this itself:
gnokey maketx call -pkgpath gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate -func Pull -send AMOUNTugnot -master SUPPORTER_ADDRESS -gas-fee 20000ugnot -gas-wanted 20000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 COLLECTOR_KEY

The repository has a collector script that finds what is due through free queries and pulls it.

For supporters

Open a plan's page: it shows the two exact commands, with the creator's collector key, the spend limit (price plus 0.1 GNOT for fees) and the period filled in. The general form:

gnokey maketx session create -pubkey COLLECTOR_GPUB -allow-paths vm/exec:gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate -spend-limit PRICE_PLUS_100000ugnot -spend-period PERIOD_SECONDS -expires-at UNIX_TIME -gas-fee 100000ugnot -gas-wanted 60000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 YOUR_KEY
gnokey maketx call -pkgpath gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate -func Subscribe -args PLAN_ID -args COLLECTOR_ADDRESS -args UNIX_TIME -gas-fee 100000ugnot -gas-wanted 60000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 YOUR_KEY

Use the same UNIX_TIME for both, at most 366 days ahead. The session must allow exactly vm/exec:gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate and nothing else, or Pull refuses it. PERIOD_SECONDS is the plan's period, at most 30 days (the chain's limit on a spend period). You can support one plan of each creator at a time: all of a creator's plans are collected by one key, and the chain allows one session per key.

Stop a mandate

Do both, with your own key. Your page (/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate:payer/YOUR_ADDRESS) shows them filled in.

gnokey maketx session revoke -pubkey COLLECTOR_GPUB -gas-fee 100000ugnot -gas-wanted 60000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 YOUR_KEY
gnokey maketx call -pkgpath gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate -func Cancel -args YOUR_ADDRESS -args COLLECTOR_ADDRESS -gas-fee 100000ugnot -gas-wanted 60000000 -broadcast -chainid onyx-1 -remote https://rpc.onyx.testnets.gno.land:443 YOUR_KEY

Checking a supporter (free)

To decide whether to deliver something to a supporter, ask how long their latest payment covers them: PaidThrough returns a unix time (0 if they never paid); deliver while now is before it. Paid time stays the supporter's after a cancel or an expiry. Do not rely on a mandate merely existing: anyone can record one without paying. A realm cannot see a session revoked on chain either, but a revoked supporter stops paying, so PaidThrough stops moving and runs out within one period. It runs out at the due time and moves on only when the creator's collector takes the next payment, so allow a grace equal to how often the collector runs (an hour, say) before treating someone as lapsed. The second query shows the chain's view of the session.

gnokey query vm/qeval -data 'gno.land/r/g1llc3lq3zmjtjdk29dk52munrzxt5ne746cl7r8/mandate.PaidThrough(address("PAYER"), PLAN_ID)' -remote https://rpc.onyx.testnets.gno.land:443
gnokey query auth/accounts/PAYER/session/COLLECTOR_ADDRESS -remote https://rpc.onyx.testnets.gno.land:443

Rules the realm enforces

  • Pull: signed with a session key as a direct call; the session allows exactly this realm; a recorded, active mandate for that payer and key; exactly the price in ugnot; at most once per period (the next one is due one period after the last); not after the expiry.
  • Every other function refuses session keys and coins.
  • The first payment can be pulled as soon as the mandate is recorded (billing in advance). A missed period is never collected later.
  • A wallet can have at most 16 sessions, so at most 16 mandates at a time.

Built on gno.land · source code: github.com/elangrr/mandate