This section applies if your Brevis app uses the "pure-ZK" model. If you want to deploy your Brevis app under the coChain model, you may skip this section.
We recommend to host your circuit as a separate process as it can take up much more computing resource than typical web servers.
Spin Up a Prover for Your AppCircuit
The fastest way to spin up a prover is to use the prover service module in the Go SDK. prover.NewService automatically compiles your circuit and sets up proving/verifying keys if your circuit changes or if it's your first time compiling. Read more about Prover Service.
main.go
proverService, err := prover.NewService(&AppCircuit{}, config)// listen to port 33247proverService.Serve(33247)
if (proofRes.has_err) {consterr=proofRes.err;switch (err.code) {caseErrCode.ERROR_INVALID_INPUT:console.error('invalid receipt/storage/transaction input:',err.msg);// handle invalid data input...// this error means some of your input// data (receipt/storage/transaction) is not found or not supported// e.g. you added a transaction of type other than 0 or 2break;caseErrCode.ERROR_INVALID_CUSTOM_INPUT:console.error('invalid custom input:',err.msg);// handle invalid custom input assignment...break;caseErrCode.ERROR_FAILED_TO_PROVE:console.error('failed to prove:',err.msg);// handle failed to prove. usually marking some record as failedbreak; }}
If you receive ERROR_INVALID_INPUT, check your data against Limits and Performance to see if any data exceeds the limits.
Tip
If you want to reuse the proofs you can do serialize and deserialize ProveResponse by:
import { Brevis } from'brevis-sdk-typescript';// A client for interacting with Brevis' systemsconstbrevis=newBrevis('appsdkv3.brevis.network:443');// submit() takes // the proof request// proof response// source chain ID where the data you want to use in your computation is from// destination chain ID where your want to post the proof toconstbrevisRes=awaitbrevis.submit(proofReq, proofRes,1,11155111);constid=brevisRes.id;constfee=brevisRes.fee;console.log(id, fee)
Pay for Your Request on the Data Source Chain
Call BrevisRequest.sendRequest() with the id acquired from brevisRes and the fee (in native token). contract addresses
Note that this step is not needed if your application is partnered with a Brevis prover that serves off-chain requests.
Wait for Your App Contract to be Called
Since Brevis calls your app contract's callback function when the final proof is submitted, you can listen to your app contract's event. Or, you could use the built-in function to wait for the final transaction submission.
// wait() takes the request id and a destination chain idbrevis.wait(brevisRes.id,11155111);