A sample workflow to use a contract as a payment processor for an off chain compute task. In this sample The payment processor exposes a function doWork
which charges a fee to access a compute function on AWS.
The fee varies based on the percentage of carbon-neutral energy being used to power the grid, for instance if more than 50% of the energy is sourced from wind, solar, hydro, etc, a reduced fee is charged.
The payment contract implements CarbonLayer to source the fuel generation mix and then uses ChainLink Functions to make a call to AWS where the compute is carried out. Finally, the result is returned to the payment contract.
Contract | Address |
---|---|
Carbon Compute | 0xcc60eD9BF0Ab6F4234e57F18AbCaAaACcA799627 |
Carbon Stats | 0x1D2C03688D0777F4A1De327c7fA76d454B4e8a62 |
- Deploy a lambda containing business logic for the compute job.
- Configure CarbonCompute to reference the lambda and parse the response.
- Deploy the CarbonCompute contract
- Follow the Managing CL Functions Subscriptions guide and make a note of your subscription id.
- Add the address as a consumer of your Chainlink Functions subscription.
- Configure the CarbonLayer renewable energy threshold for your use case using setThreshold, e.g.
setThreshold(600)
sets a requirement for a 60% renewable energy source. - Configure the standard and reduced fees using setFees, e.g.
setFees(2000000000000000, 1000000000000000)
sets a fee of 0.002 ETH and a reduced fee of 0.001 ETH.