Skip to main content

Ethereum Virtual Machine (EVM)

Acurast can be used to get access to computational resources for various use cases and bring them to EVM chains. For that, the Consumer creates a Job that performs a given task on the Acurast Console.

Integration Example

The following example shows a possible integration approach for an EVM chain.

EVM smart contract implementation

The first step is the implementation and deployment of the EVM contract.

The example used is a simple entropy provider, which receives entropy from an Acurast Processor and exposes it to other contracts in the EVM environment.

In this example, the contract expects the Acurast Processor to be known in advance, this can also be adapted at a later stage, depending on how you want to assign your Job to one or more Processors.

For simplicity purposes, this example uses the address 0x176583fbcd4e378c138dea7a4630e7b2b759af96 as a Processor.

Deploy with Remix

EntropyProvider.sol
// SPDX-License-Identifier: None
pragma solidity ^0.8.0;

contract EntropyProvider {
bytes entropy;
uint last_update;
address processor;

constructor(address _processor) {
processor = _processor;
}

/**
* Receive entropy (random bytes) from an Acurast job.
*/
function receive_entropy(bytes memory _entropy) public {
// Ensures that only the processor can call this function
require(msg.sender == processor, "NOT_ALLOWED");
// Update entropy
entropy = _entropy;
last_update = block.timestamp;
}

/**
* A view that exposes the entropy to other contracts.
*/
function consume_entropy(uint maxAge) public view returns (bytes memory) {
// Consumers can specify the maximum entropy age they are willing to accept
require(block.timestamp - last_update <= maxAge, "ENTROPY_TOO_OLD");

return entropy;
}
}

Deployed contract example on Goerli chain: 0x2c503cfba7178eb0ac2dc5df45279527d437657a

Job specification

Now that the contract has been deployed, we can prepare the script that will get executed by the Processor to provision the entropy.

The script below computes some random bytes securely and calls the function receive_entropy of the contract deployed above. The Consumer can also specify the gas limit and maximum costs per gas unit.

JobLogic.js
// Destination contract address
const destination = "<0x evm_contract_address>";
// Generate entropy
const entropy = _STD_.random.generateSecureRandomHex();
// Fulfill entropy
_STD_.chains.ethereum.fulfill(
"https://rpc.ankr.com/eth_goerli", // RPC
destination, // Destination contract address
entropy, // Payload
// Transaction parameters
{
methodSignature: "receive_entropy(bytes)",
gasLimit: "9000000",
maxFeePerGas: "255000000000",
maxPriorityFeePerGas: "2550000000",
},
// Success callback
(opHash) => {
print("Succeeded: " + opHash);
},
// Error callback
(err) => {
print("Failed: " + err);
}
);
https://example.com

Job Registration

Check out How to get started with the Acurast Console to register your Job.