Skip to content

Solidity API

IMarketplace

Interface for creating new ERC20 based node provider

ValidatorNodeProviderCreated

solidity
event ValidatorNodeProviderCreated(contract IValidatorNodeProvider provider, contract IConsensus consensus, contract IERC20 token, address payee, uint256 price)

A new provider was created

Parameters

NameTypeDescription
providercontract IValidatorNodeProviderThe address of the provider
consensuscontract IConsensusThe consensus associated with the provider
tokencontract IERC20The token used for billing
payeeaddressThe address that will receive the payments
priceuint256The price per second of application node execution

ReaderNodeProviderCreated

solidity
event ReaderNodeProviderCreated(contract IReaderNodeProvider provider, contract IERC20 token, address payee, uint256 price)

A new provider was created

Parameters

NameTypeDescription
providercontract IReaderNodeProviderThe address of the provider
tokencontract IERC20The token used for billing
payeeaddressThe address that will receive the payments
priceuint256The price per second of application node execution

newValidatorNodeProvider

solidity
function newValidatorNodeProvider(contract IConsensus consensus, contract IERC20 token, address payee, uint256 price) external returns (contract IValidatorNodeProvider)

Create a new ERC20 based ValidatorNodeProvider using the specified token

Parameters

NameTypeDescription
consensuscontract IConsensusThe consensus associated with the provider
tokencontract IERC20The token used for billing
payeeaddressThe address that will receive the payments
priceuint256The price per second of application node execution

newReaderNodeProvider

solidity
function newReaderNodeProvider(contract IERC20 token, address payee, uint256 price) external returns (contract IReaderNodeProvider)

Create a new ERC20 based ReaderNodeProvider using the specified token

Parameters

NameTypeDescription
tokencontract IERC20The token used for billing
payeeaddressThe address that will receive the payments
priceuint256The price per second of application node execution

Marketplace

Factory for creating new ERC20 based providers

ens

solidity
contract ENS ens

factory

solidity
contract ICartesiDAppFactory factory

constructor

solidity
constructor(contract ENS _ens, contract ICartesiDAppFactory _factory) public

newValidatorNodeProvider

solidity
function newValidatorNodeProvider(contract IConsensus _consensus, contract IERC20 _token, address _payee, uint256 _price) external returns (contract IValidatorNodeProvider)

Create a new ERC20 based ValidatorNodeProvider using the specified token

newReaderNodeProvider

solidity
function newReaderNodeProvider(contract IERC20 _token, address _payee, uint256 _price) external returns (contract IReaderNodeProvider)

Create a new ERC20 based ReaderNodeProvider using the specified token

IVault

Vault interface that adds a payment specification for the execution of application nodes

The implementation should specify a token as payment method, and calculate the price for a specified amount of execution time of the application node.

cost

solidity
function cost(uint256 _time) external view returns (uint256)

Returns the cost of running an application for a given time

Parameters

NameTypeDescription
_timeuint256The time in seconds

Return Values

NameTypeDescription
[0]uint256The cost in amount of ERC-20 tokens

token

solidity
function token() external view returns (contract IERC20)

The token used by the vault

payee

solidity
function payee() external view returns (address)

The address which will receive payments for the application node execution

runway

solidity
function runway(contract ICartesiDApp _application) external view returns (uint256)

Returns the runway of a given application

Runway is the amount of time (in seconds) an application node has funds to run

Parameters

NameTypeDescription
_applicationcontract ICartesiDAppThe application address

extendRunway

solidity
function extendRunway(contract ICartesiDApp _application, uint256 _time) external returns (uint256)

Extend the runway of a given application by an amount of time

The user must approve the token transfer from the caller to the payee beforehand.

Parameters

NameTypeDescription
_applicationcontract ICartesiDAppThe application
_timeuint256The amount of time to extend the runway (will trigger transfer)

Vault

This contract implements an IVault, using an ERC-20 token and a fixed price per unit of time.

price

solidity
uint256 price

token

solidity
contract IERC20 token

The token used by the vault

payee

solidity
address payee

The address which will receive payments for the application node execution

runway

solidity
mapping(contract ICartesiDApp => uint256) runway

Returns the runway of a given application

Runway is the amount of time (in seconds) an application node has funds to run

Parameters

NameTypeDescription

constructor

solidity
constructor(address _owner, contract IERC20 _token, address _payee, uint256 _price) public

Construct a new Vault with the given token as payment method and price

Parameters

NameTypeDescription
_owneraddressThe owner of the vault, who can pause its operation
_tokencontract IERC20The token to use as payment method
_payeeaddressThe receiver of the payments to applications managed by this vault
_priceuint256The price per second of execution of the application node

cost

solidity
function cost(uint256 _time) public view returns (uint256)

Returns the cost of running an application for a given time

Parameters

NameTypeDescription
_timeuint256The time in seconds

Return Values

NameTypeDescription
[0]uint256The cost in amount of ERC-20 tokens

extendRunway

solidity
function extendRunway(contract ICartesiDApp _application, uint256 _time) external returns (uint256)

Extend the runway of a given application by an amount of time

The user must approve the token transfer from the caller to the payee beforehand.

Parameters

NameTypeDescription
_applicationcontract ICartesiDAppThe application
_timeuint256The amount of time to extend the runway (will trigger transfer)

_extendRunway

solidity
function _extendRunway(address _msgSender, contract ICartesiDApp _application, uint256 _time) internal returns (uint256)

pause

solidity
function pause() public

unpause

solidity
function unpause() public

IFinancialProtocol

Interface that should be implemented by any contract which dictates the financial incentives of the execution of validator nodes for Cartesi applications.

FinancialRunway

solidity
event FinancialRunway(address application, uint256 until)

Signals until when a application has enough funds to be validated

This event signals until when the validator node for the application should be running. The offchain implementation which controls the execution of validator nodes is free to choose which implementation contracts they will rely on for this information.

Parameters

NameTypeDescription
applicationaddressThe application address
untiluint256The point in time when the application will run out of funds (seconds since epoch)

IMachineProtocol

Interface that should be implemented by any contract which controls the association of a deployed Cartesi application to its offchain Cartesi Machine snapshot.

MachineLocation

solidity
event MachineLocation(address application, string location)

Signals the association of a application to its offchain Cartesi Machine

This event signals the association of an on-chain deployed Cartesi application to the offchain location of the snapshot of the Cartesi machine corresponding to the template hash stored on-chain. The format or protocol of the location field is not enforced on-chain and can follow any format, like a URL or an IPFS CID.

Parameters

NameTypeDescription
applicationaddressThe application address
locationstringThe storage location of the Cartesi machine snapshot

INodeProvider

register

solidity
function register(contract ICartesiDApp application, string location) external

Register an application with the node provider

Parameters

NameTypeDescription
applicationcontract ICartesiDAppThe application to be registered
locationstringThe Cartesi machine snapshot location

setName

solidity
function setName(string _name) external

Sets a name for the provider using ENS service

Parameters

NameTypeDescription
_namestringThe name of the provider

IReaderNodeProvider

IValidatorNodeProvider

consensus

solidity
function consensus() external view returns (contract IConsensus)

The consensus wired to the provider

deploy

solidity
function deploy(address _owner, bytes32 _templateHash, string _location, uint256 _initialRunway) external returns (contract CartesiDApp)

Deploy a new application

Parameters

NameTypeDescription
_owneraddressThe address that will own the application
_templateHashbytes32The hash of the initial state of the Cartesi Machine
_locationstringThe Cartesi machine snapshot location
_initialRunwayuint256The initial runway of the application in seconds

Return Values

NameTypeDescription
[0]contract CartesiDAppThe application

deploy

solidity
function deploy(address _owner, bytes32 _templateHash, string _location, uint256 _initialRunway, bytes32 _salt) external returns (contract CartesiDApp)

Deploy a new application deterministically

Parameters

NameTypeDescription
_owneraddressThe address that will own the application
_templateHashbytes32The hash of the initial state of the Cartesi Machine
_locationstringThe Cartesi machine snapshot location
_initialRunwayuint256The initial runway of the application in seconds
_saltbytes32The salt used to deterministically generate the application address

Return Values

NameTypeDescription
[0]contract CartesiDAppThe application

calculateApplicationAddress

solidity
function calculateApplicationAddress(address _owner, bytes32 _templateHash, bytes32 _salt) external view returns (address)

Calculate the address of an application to be deployed deterministically.

Beware that only the deploy function with the salt parameter is able to deterministically deploy an application.

Parameters

NameTypeDescription
_owneraddressThe address that will own the application
_templateHashbytes32The hash of the initial state of the Cartesi Machine
_saltbytes32The salt used to deterministically generate the application address

Return Values

NameTypeDescription
[0]addressThe application address

NodeProvider

ens

solidity
contract ENS ens

constructor

solidity
constructor(address _owner, contract ENS _ens, contract IERC20 _token, address _payee, uint256 _price) internal

setName

solidity
function setName(string name) external

ReaderNodeProvider

constructor

solidity
constructor(address _owner, contract ENS _ens, contract IERC20 _token, address _payee, uint256 _price) public

register

solidity
function register(contract ICartesiDApp application, string location) external

Register an application with the node provider

Parameters

NameTypeDescription
applicationcontract ICartesiDAppThe application to be registered
locationstringThe Cartesi machine snapshot location

ValidatorNodeProvider

factory

solidity
contract ICartesiDAppFactory factory

consensus

solidity
contract IConsensus consensus

The consensus wired to the provider

constructor

solidity
constructor(address _owner, contract ENS _ens, contract IERC20 _token, address _payee, uint256 _price, contract ICartesiDAppFactory _factory, contract IConsensus _consensus) public

register

solidity
function register(contract ICartesiDApp application, string location) external

Register an application with the node provider

Parameters

NameTypeDescription
applicationcontract ICartesiDAppThe application to be registered
locationstringThe Cartesi machine snapshot location

deploy

solidity
function deploy(address _owner, bytes32 _templateHash, string _location, uint256 _initialRunway) external returns (contract CartesiDApp)

This function deploys a new application, and registers it with the payment system

deploy

solidity
function deploy(address _owner, bytes32 _templateHash, string _location, uint256 _initialRunway, bytes32 _salt) external returns (contract CartesiDApp)

This function deploys a new application deterministically, and registers it with the payment system

calculateApplicationAddress

solidity
function calculateApplicationAddress(address _owner, bytes32 _templateHash, bytes32 _salt) external view returns (address)

This function calculates the application deterministically