REPL-only functions
The following functions are loaded automatically into the interactive REPL, or
within script files with a .repl
extension. They are not available for
blockchain-based execution.
begin-tx
→ string
name string
→ string
Begin transaction with optional NAME.
pact> (begin-tx "load module")"Begin Tx 0: load module"
pact> (begin-tx "load module")"Begin Tx 0: load module"
bench
exprs *
→ string
Benchmark execution of EXPRS.
(bench (+ 1 2))
(bench (+ 1 2))
commit-tx
→ string
Commit transaction.
pact> (begin-tx) (commit-tx)"Commit Tx 0"
pact> (begin-tx) (commit-tx)"Commit Tx 0"
continue-pact
step integer
→ string
step integer
rollback bool
→ string
step integer
rollback bool
pact-id string
→ string
step integer
rollback bool
pact-id string
yielded object:<{y}>
→ string
Continue previously-initiated pact identified STEP, optionally specifying ROLLBACK (default is false), PACT-ID of the pact to be continued (defaults to the pact initiated in the current transaction, if one is present), and YIELDED value to be read with 'resume' (if not specified, uses yield in most recent pact exec, if any).
(continue-pact 1)(continue-pact 1 true)(continue-pact 1 false "[pact-id-hash]"))(continue-pact 2 1 false "[pact-id-hash]" { "rate": 0.9 })
(continue-pact 1)(continue-pact 1 true)(continue-pact 1 false "[pact-id-hash]"))(continue-pact 2 1 false "[pact-id-hash]" { "rate": 0.9 })
env-chain-data
new-data object:~{public-chain-data}
→ string
Update existing entries of 'chain-data' with NEW-DATA, replacing those items only.
pact> (env-chain-data { "chain-id": "TestNet00/2", "block-height": 20 })"Updated public metadata"
pact> (env-chain-data { "chain-id": "TestNet00/2", "block-height": 20 })"Updated public metadata"
env-data
json <a[integer,string,time,decimal,bool,[<l>],object:<{o}>,keyset]>
→ string
Set transaction JSON data, either as encoded string, or as pact types coerced to JSON.
pact> (env-data { "keyset": { "keys": ["my-key" "admin-key"], "pred": "keys-any" } })"Setting transaction data"
pact> (env-data { "keyset": { "keys": ["my-key" "admin-key"], "pred": "keys-any" } })"Setting transaction data"
env-dynref
iface module
impl module{}
→ string
→ string
Substitute module IMPL in any dynamic usages of IFACE in typechecking and analysis. With no arguments, remove all substitutions.
(env-dynref fungible-v2 coin)
(env-dynref fungible-v2 coin)
env-enable-repl-natives
enable bool
→ string
Control whether REPL native functions are allowed in module code. When enabled, fixture functions like 'env-sigs' are allowed in module code.
pact> (env-enable-repl-natives true)"Repl natives enabled"
pact> (env-enable-repl-natives true)"Repl natives enabled"
env-entity
→ string
entity string
→ string
Set environment confidential ENTITY id, or unset with no argument.
(env-entity "my-org")(env-entity)
(env-entity "my-org")(env-entity)
env-events
clear bool
→ [object:*]
Retreive any accumulated events and optionally clear event state. Object returned has fields 'name' (fully-qualified event name), 'params' (event parameters), 'module-hash' (hash of emitting module).
(env-events true)
(env-events true)
env-exec-config
flags [string]
→ [string]
→ [string]
Queries, or with arguments, sets execution config flags. Valid flags: ["AllowReadInLocal","DisableHistoryInTransactionalMode","DisableInlineMemCheck","DisableModuleInstall","DisableNewTrans","DisablePact40","DisablePact420","DisablePact43","DisablePact431","DisablePact44","DisablePact45","DisablePact46","DisablePact47","DisablePact48","DisablePactEvents","DisableRuntimeReturnTypeChecking","EnforceKeyFormats","OldReadOnlyBehavior","PreserveModuleIfacesBug","PreserveModuleNameBug","PreserveNsModuleInstallBug","PreserveShowDefs"]
pact> (env-exec-config ['DisableHistoryInTransactionalMode]) (env-exec-config)["DisableHistoryInTransactionalMode"]
pact> (env-exec-config ['DisableHistoryInTransactionalMode]) (env-exec-config)["DisableHistoryInTransactionalMode"]
env-gas
→ integer
gas integer
→ string
Query gas state, or set it to GAS. Note that certain plaforms may charge additional gas that is not captured by the interpreter gas model, such as an overall transaction-size cost.
pact> (env-gasmodel "table") (env-gaslimit 10) (env-gas 0) (map (+ 1) [1 2 3]) (env-gas)7
pact> (env-gasmodel "table") (env-gaslimit 10) (env-gas 0) (map (+ 1) [1 2 3]) (env-gas)7
env-gaslimit
limit integer
→ string
Set environment gas limit to LIMIT.
env-gaslog
→ string
Enable and obtain gas logging. Bracket around the code whose gas logs you want to inspect.
pact> (env-gasmodel "table") (env-gaslimit 10) (env-gaslog) (map (+ 1) [1 2 3]) (env-gaslog)["TOTAL: 7" "map:GUnreduced:currTotalGas=4: 4" "+:GUnreduced:currTotalGas=5: 1" ":GIntegerOpCost:(1, ):(1, ):currTotalGas=5: 0" "+:GUnreduced:currTotalGas=6: 1" ":GIntegerOpCost:(1, ):(2, ):currTotalGas=6: 0" "+:GUnreduced:currTotalGas=7: 1" ":GIntegerOpCost:(1, ):(3, ):currTotalGas=7: 0"]
pact> (env-gasmodel "table") (env-gaslimit 10) (env-gaslog) (map (+ 1) [1 2 3]) (env-gaslog)["TOTAL: 7" "map:GUnreduced:currTotalGas=4: 4" "+:GUnreduced:currTotalGas=5: 1" ":GIntegerOpCost:(1, ):(1, ):currTotalGas=5: 0" "+:GUnreduced:currTotalGas=6: 1" ":GIntegerOpCost:(1, ):(2, ):currTotalGas=6: 0" "+:GUnreduced:currTotalGas=7: 1" ":GIntegerOpCost:(1, ):(3, ):currTotalGas=7: 0"]
env-gasmodel
model string
→ string
→ string
model string
rate integer
→ string
Update or query current gas model. With just MODEL, "table" is supported; with MODEL and RATE, 'fixed' is supported. With no args, output current model.
pact> (env-gasmodel)"Current gas model is 'fixed 0': constant rate gas model with fixed rate 0"pact> (env-gasmodel 'table)"Set gas model to table-based cost model"pact> (env-gasmodel 'fixed 1)"Set gas model to constant rate gas model with fixed rate 1"
pact> (env-gasmodel)"Current gas model is 'fixed 0': constant rate gas model with fixed rate 0"pact> (env-gasmodel 'table)"Set gas model to table-based cost model"pact> (env-gasmodel 'fixed 1)"Set gas model to constant rate gas model with fixed rate 1"
env-gasprice
price decimal
→ string
Set environment gas price to PRICE.
env-gasrate
rate integer
→ string
Update gas model to charge constant RATE.
env-hash
hash string
→ string
Set current transaction hash. HASH must be an unpadded base64-url encoded BLAKE2b 256-bit hash.
pact> (env-hash (hash "hello"))"Set tx hash to Mk3PAn3UowqTLEQfNlol6GsXPe-kuOWJSCU0cbgbcs8"
pact> (env-hash (hash "hello"))"Set tx hash to Mk3PAn3UowqTLEQfNlol6GsXPe-kuOWJSCU0cbgbcs8"
env-keys
keys [string]
→ string
DEPRECATED in favor of 'env-sigs'. Set transaction signer KEYS. See 'env-sigs' for setting keys with associated capabilities.
pact> (env-keys ["my-key" "admin-key"])"Setting transaction keys"
pact> (env-keys ["my-key" "admin-key"])"Setting transaction keys"
env-namespace-policy
allow-root bool
ns-policy-fun ns:string ns-admin:guard -> bool
→ string
Install a managed namespace policy specifying ALLOW-ROOT and NS-POLICY-FUN.
(env-namespace-policy (my-ns-policy-fun))
(env-namespace-policy (my-ns-policy-fun))
env-sigs
sigs [object:*]
→ string
Set transaction signature keys and capabilities. SIGS is a list of objects with "key" specifying the signer key, and "caps" specifying a list of associated capabilities.
(env-sigs [{'key: "my-key", 'caps: [(accounts.USER_GUARD "my-account")]}, {'key: "admin-key", 'caps: []}
(env-sigs [{'key: "my-key", 'caps: [(accounts.USER_GUARD "my-account")]}, {'key: "admin-key", 'caps: []}
env-simulate-onchain
on-chain bool
→ string
Set a flag to simulate on-chain behavior that differs from the repl, in particular for observing things like errors and stack traces.
(env-simulate-onchain true)
(env-simulate-onchain true)
expect
doc string
expected <a>
actual <a>
→ string
Evaluate ACTUAL and verify that it equals EXPECTED.
pact> (expect "Sanity prevails." 4 (+ 2 2))"Expect: success: Sanity prevails."
pact> (expect "Sanity prevails." 4 (+ 2 2))"Expect: success: Sanity prevails."
expect-failure
doc string
exp <a>
→ string
doc string
err string
exp <a>
→ string
Evaluate EXP and succeed only if it throws an error.
pact> (expect-failure "Enforce fails on false" (enforce false "Expected error"))"Expect failure: success: Enforce fails on false"pact> (expect-failure "Enforce fails with message" "Expected error" (enforce false "Expected error"))"Expect failure: success: Enforce fails with message"
pact> (expect-failure "Enforce fails on false" (enforce false "Expected error"))"Expect failure: success: Enforce fails on false"pact> (expect-failure "Enforce fails with message" "Expected error" (enforce false "Expected error"))"Expect failure: success: Enforce fails with message"
expect-that
doc string
pred value:<a> -> bool
exp <a>
→ string
Evaluate EXP and succeed if value passes predicate PRED.
pact> (expect-that "addition" (< 2) (+ 1 2))"Expect-that: success: addition"pact> (expect-that "addition" (> 2) (+ 1 2))"FAILURE: addition: did not satisfy (> 2) : 3:integer"
pact> (expect-that "addition" (< 2) (+ 1 2))"Expect-that: success: addition"pact> (expect-that "addition" (> 2) (+ 1 2))"FAILURE: addition: did not satisfy (> 2) : 3:integer"
format-address
scheme string
public-key string
→ string
Transform PUBLIC-KEY into an address (i.e. a Pact Runtime Public Key) depending on its SCHEME.
load
file string
→ string
file string
reset bool
→ string
Load and evaluate FILE, resetting repl state beforehand if optional RESET is true.
(load "accounts.repl")
(load "accounts.repl")
mock-spv
type string
payload object:*
output object:*
→ string
Mock a successful call to 'spv-verify' with TYPE and PAYLOAD to return OUTPUT.
(mock-spv "TXOUT" { 'proof: "a54f54de54c54d89e7f" } { 'amount: 10.0, 'account: "Dave", 'chainId: "1" })
(mock-spv "TXOUT" { 'proof: "a54f54de54c54d89e7f" } { 'amount: 10.0, 'account: "Dave", 'chainId: "1" })
pact-state
→ object:*
clear bool
→ object:*
Inspect state from most recent pact execution. Returns object with fields 'pactId': pact ID; 'yield': yield result or 'false' if none; 'step': executed step; 'executed': indicates if step was skipped because entity did not match. With CLEAR argument, erases pact from repl state.
(pact-state)(pact-state true)
(pact-state)(pact-state true)
value <a>
→ string
Output VALUE to terminal as unquoted, unescaped text.
rollback-tx
→ string
Rollback transaction.
pact> (begin-tx "Third Act") (rollback-tx)"Rollback Tx 0: Third Act"
pact> (begin-tx "Third Act") (rollback-tx)"Rollback Tx 0: Third Act"
sig-keyset
→ keyset
Convenience function to build a keyset from keys present in message signatures, using 'keys-all' as the predicate.
test-capability
capability -> bool
→ string
Acquire (if unmanaged) or install (if managed) CAPABILITY. CAPABILITY and any composed capabilities are in scope for the rest of the transaction.
(test-capability (MY-CAP))
(test-capability (MY-CAP))
typecheck
module string
→ string
module string
debug bool
→ string
Typecheck MODULE, optionally enabling DEBUG output.
verify
module string
debug bool
→ string
Verify MODULE, checking that all properties hold. Optionally, if DEBUG is set to true, write debug output to "pact-verify-MODULE" directory.
(verify "module")(verify "module" true)
(verify "module")(verify "module" true)
with-applied-env
exec <a>
→ <a>
Evaluate EXEC with any pending environment changes applied. Normally, environment changes must execute at top-level for the change to take effect. This allows scoped application of non-toplevel environment changes.
pact> (let ((a 1)) (env-data { 'b: 1 }) (with-applied-env (+ a (read-integer 'b))))2
pact> (let ((a 1)) (env-data { 'b: 1 }) (with-applied-env (+ a (read-integer 'b))))2