Contracts

Last updated 4 months ago

get
Active Contract Set

http://127.0.0.1:31567
/contract/active
Returns all currently active contracts. May not be accurate until the blockchain is fully synced.
Request
Response
200: OK
An array of contract objects, including their actual F-Star code.
[
{
"contractHash": "55be2edd1e537869cce832bd014aa1e3251aba651c5c3f38f70db86417faa9c4",
"address": "tc1q2klzahg72duxnn8gx27szj4puvj34wn9r3wr7w8hpkuxg9l648zqhc76xa",
"expire": 19375,
"code": "(* NAME_START: Example Token :NAME_END *)\nopen Zen.Types\nopen Zen.Vector\nopen Zen.Base\nopen Zen.Cost\nopen Zen.Asset\nopen Zen.Data\n\nmodule ET = Zen.ErrorT\nmodule OT = Zen.OptionT\nmodule Tx = Zen.TxSkeleton\nmodule CR = Zen.ContractResult.NoMessage\n\nlet buy txSkeleton contractHash returnAddress =\n let! tokens = Tx.getAvailableTokens zenAsset txSkeleton in\n\n let! contractAsset = getDefault contractHash in\n\n let! txSkeleton =\n Tx.lockToContract zenAsset tokens contractHash txSkeleton\n >>= Tx.mint tokens contractAsset\n >>= Tx.lockToAddress contractAsset tokens returnAddress in\n\n CR.ret txSkeleton\n\nlet redeem txSkeleton contractHash returnAddress wallet =\n let! contractAsset = getDefault contractHash in\n let! tokens = Tx.getAvailableTokens contractAsset txSkeleton in\n\n let! txSkeleton =\n Tx.destroy tokens contractAsset txSkeleton\n >>= Tx.lockToAddress zenAsset tokens returnAddress\n >>= Tx.fromWallet zenAsset tokens contractHash wallet in\n\n CR.ofOption \"contract doesn't have enough zens to pay you\" txSkeleton\n\nval main: txSkeleton -> hash -> string -> option data -> wallet:wallet -> cost (result (txSkeleton ** option message)) (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)\nlet main txSkeleton contractHash command data wallet =\n let! returnAddress = data >!> tryDict >?> tryFindLock \"returnAddress\" in\n\n match returnAddress with\n | Some returnAddress ->\n if command = \"redeem\" then\n redeem txSkeleton contractHash returnAddress wallet\n else if command = \"\" || command = \"buy\" then\n buy txSkeleton contractHash returnAddress\n |> autoInc\n else\n ET.autoFailw \"unsupported command\"\n | None ->\n ET.autoFailw \"returnAddress is required\"\n\nval cf: txSkeleton -> string -> option data -> wallet -> cost nat 24\nlet cf _ _ _ wallet = ret (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)"
},
{
"contractHash": "55be2edd1e537869cce832bd014aa1e3251aba651c5c3f38f70db86417faa9c4",
"address": "tc1q2klzahg72duxnn8gx27szj4puvj34wn9r3wr7w8hpkuxg9l648zqhc76xa",
"expire": 19375,
"code": "(* NAME_START: Example Token :NAME_END *)\nopen Zen.Types\nopen Zen.Vector\nopen Zen.Base\nopen Zen.Cost\nopen Zen.Asset\nopen Zen.Data\n\nmodule ET = Zen.ErrorT\nmodule OT = Zen.OptionT\nmodule Tx = Zen.TxSkeleton\nmodule CR = Zen.ContractResult.NoMessage\n\nlet buy txSkeleton contractHash returnAddress =\n let! tokens = Tx.getAvailableTokens zenAsset txSkeleton in\n\n let! contractAsset = getDefault contractHash in\n\n let! txSkeleton =\n Tx.lockToContract zenAsset tokens contractHash txSkeleton\n >>= Tx.mint tokens contractAsset\n >>= Tx.lockToAddress contractAsset tokens returnAddress in\n\n CR.ret txSkeleton\n\nlet redeem txSkeleton contractHash returnAddress wallet =\n let! contractAsset = getDefault contractHash in\n let! tokens = Tx.getAvailableTokens contractAsset txSkeleton in\n\n let! txSkeleton =\n Tx.destroy tokens contractAsset txSkeleton\n >>= Tx.lockToAddress zenAsset tokens returnAddress\n >>= Tx.fromWallet zenAsset tokens contractHash wallet in\n\n CR.ofOption \"contract doesn't have enough zens to pay you\" txSkeleton\n\nval main: txSkeleton -> hash -> string -> option data -> wallet:wallet -> cost (result (txSkeleton ** option message)) (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)\nlet main txSkeleton contractHash command data wallet =\n let! returnAddress = data >!> tryDict >?> tryFindLock \"returnAddress\" in\n\n match returnAddress with\n | Some returnAddress ->\n if command = \"redeem\" then\n redeem txSkeleton contractHash returnAddress wallet\n else if command = \"\" || command = \"buy\" then\n buy txSkeleton contractHash returnAddress\n |> autoInc\n else\n ET.autoFailw \"unsupported command\"\n | None ->\n ET.autoFailw \"returnAddress is required\"\n\nval cf: txSkeleton -> string -> option data -> wallet -> cost nat 24\nlet cf _ _ _ wallet = ret (2 + 66 + (64 + (64 + (64 + 64 + (Zen.Wallet.size wallet * 128 + 192) + 0)) + 25) + 29)"
}
]

get
Contract ID

http://127.0.0.1:31567
/contract/contractId
Get a contract identifier from a contract address.
Request
Response
Path Parameters
address
required
string
address of the contract
200: OK
Contract ID
400: Bad Request
invalid address map
[("address",
"notExistingContractAddress")]

post
Activate Contract

http://127.0.0.1:31567
/wallet/contract/activate
This how you activate a contract
Request
Response
Body Parameters
password
required
string
wallet password
numberOfBlocks
required
number
The number of blocks you want to activate your contract for
code
required
string
Send valid fstar code, for example: let main _ _ _ _ _ _ _ _ = Zen.ResultT.failw \"This contract does nothing\"\nlet cf _ _ _ _ _ _ _ = Zen.Cost.ret (1 <: nat)
200: OK
Cake successfully retrieved.
{
"address": "ctzn1qqqqqqqym4kfe8y5qg5tazkgjwn4qpesj05x6mqsvd5auwmzkhhs444fnkvwxhahr",
"contractId": "000000009bad939392804517d1591274ea00e6127d0dad820c6d3bc76c56bde15ad533b3"
}
400: Bad Request
Could not find a matching in the query.

post
Execute Contract

http://127.0.0.1:31567
/wallet/contract/execute
Run a smart contract with parameters
Request
Response
Body Parameters
sign
required
string
sign hash
password
required
string
wallet password
returnAddress
required
boolean
Execute the contract with some default arguments, such as: - returnAddress - allows the contract to automatically send funds back to in case it needs to. { "returnAddress" : true/false }
message
optional
string
send the contract some data
contractId
required
string
The contract address
command
required
string
Trigger one of the functions in the contract such as: "buy" / "redeem"
spends
required
array
an array of outputs
200: OK

post
Extend Contract

http://127.0.0.1:31567
/wallet/contract/extend
This is to extend a contract
Request
Response
Body Parameters
password
required
string
wallet password
numberOfBlocks
required
string
Number of block until when the contract will be active
contractId
required
string
ID of the contract
200: OK