Submits a proof to the batcher to be verified and returns an aligned verification data struct.
pub async fn submit(
batcher_url: &str,
network: Network,
verification_data: &VerificationData,
max_fee; U256,
wallet: Wallet<SigningKey>,
nonce: U256,
) -> Result<AlignedVerificationData, errors::SubmitError>batcher_url- The url of the batcher to which the proof will be submitted.network- The network on which the proof will be submitted (devnet | holesky-stage | holesky)verification_data- The verification data for the proof.max_fee- The maximum fee that the submitter is willing to pay for the proof verification.wallet- The wallet used to sign the proof. Should be using correct chain id. Seeget_chain_id.nonce- The nonce of the submitter address. Seeget_nonce_from_ethereum.
Result<AlignedVerificationData, SubmitError>- An aligned verification data or an error.
MissingRequiredParameterif the verification data vector is empty.ProtocolVersionMismatchif the version of the SDK is lower than the expected one.UnexpectedBatcherResponseif the batcher doesn't respond with the expected message.SerializationErrorif there is an error deserializing the message sent from the batcher.WebSocketConnectionErrorif there is an error connecting to the batcher.WebSocketClosedUnexpectedlyErrorif the connection with the batcher is closed unexpectedly.InvalidSignatureif the signature is invalid.InvalidNonceif the nonce is invalid.InvalidMaxFeeif the max fee is invalid.InvalidProofif the proof is invalid.ProofTooLargeif the proof is too large.InsufficientBalanceif the sender balance is not enough or unlockedProofQueueFlushedif there is an error in the batcher and the proof queue is flushed.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.GenericErrorif the error doesn't match any of the previous ones.
Submits multiple proofs to the batcher to be verified and returns an aligned verification data array.
pub async fn submit_multiple(
batcher_url: &str,
network: Network,
verification_data: &[VerificationData],
max_fees: &[U256],
wallet: Wallet<SigningKey>,
nonce: U256,
) -> Result<Vec<AlignedVerificationData>, errors::SubmitError>batcher_url- The url of the batcher to which the proof will be submitted.network- The network on which the proof will be submitted (devnet | holesky-stage | holesky)verification_data- A verification data array.max_fees- A max fee array.wallet- The wallet used to sign the proof. Should be using correct chain id. Seeget_chain_id.nonce- The nonce of the submitter address. Seeget_nonce_from_ethereum.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.
Result<Vec<AlignedVerificationData>, SubmitError>- An aligned verification data array or an error.
MissingRequiredParameterif the verification data vector is empty.ProtocolVersionMismatchif the version of the SDK is lower than the expected one.UnexpectedBatcherResponseif the batcher doesn't respond with the expected message.SerializationErrorif there is an error deserializing the message sent from the batcher.WebSocketConnectionErrorif there is an error connecting to the batcher.WebSocketClosedUnexpectedlyErrorif the connection with the batcher is closed unexpectedly.InvalidSignatureif the signature is invalid.InvalidNonceif the nonce is invalid.InvalidMaxFeeif the max fee is invalid.InvalidProofif the proof is invalid.ProofTooLargeif the proof is too large.InsufficientBalanceif the sender balance is not enough or unlockedProofQueueFlushedif there is an error in the batcher and the proof queue is flushed.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.GenericErrorif the error doesn't match any of the previous ones.
Submits a proof to the batcher to be verified, waits for the verification on ethereum and returns an aligned verification data struct.
pub async fn submit_and_wait_verification(
batcher_url: &str,
eth_rpc_url: &str,
network: Network,
verification_data: &VerificationData,
max_fee: U256,
wallet: Wallet<SigningKey>,
nonce: U256,
) -> Result<AlignedVerificationData, errors::SubmitError>batcher_url- The url of the batcher to which the proof will be submitted.eth_rpc_url- The URL of the Ethereum RPC node.network- The network on which the verification will be done (devnet | holesky-stage | holesky)verification_data- The verification data for the proof.max_fee- The maximum fee that the submitter is willing to pay for the proof verification.wallet- The wallet used to sign the proof. Should be using correct chain id. Seeget_chain_id.nonce- The nonce of the submitter address. Seeget_nonce_from_ethereum.payment_service_addr- The address of the batcher payment service contract.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.
Result<AlignedVerificationData, SubmitError>- An aligned verification data or an error.
MissingRequiredParameterif the verification data vector is empty.ProtocolVersionMismatchif the version of the SDK is lower than the expected one.UnexpectedBatcherResponseif the batcher doesn't respond with the expected message.SerializationErrorif there is an error deserializing the message sent from the batcher.WebSocketConnectionErrorif there is an error connecting to the batcher.WebSocketClosedUnexpectedlyErrorif the connection with the batcher is closed unexpectedly.EthereumProviderErrorif there is an error in the connection with the RPC provider.HexDecodingErrorif there is an error decoding the Aligned service manager contract address.BatchVerificationTimeoutif there is a timeout waiting for the batch verification.InvalidSignatureif the signature is invalid.InvalidNonceif the nonce is invalid.InvalidMaxFeeif the max fee is invalid.InvalidProofif the proof is invalid.ProofTooLargeif the proof is too large.InsufficientBalanceif the sender balance is not enough or unlockedProofQueueFlushedif there is an error in the batcher and the proof queue is flushed.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.GenericErrorif the error doesn't match any of the previous ones.
Submits multiple proofs to the batcher for verification, waits for verification on Ethereum, and returns an array of Results containing aligned verification data that indicates whether each proof was successfully submitted. If a timeout occurs while waiting for verification, an additional Err is appended to the end of the returned array.
pub async fn submit_multiple_and_wait_verification(
batcher_url: &str,
eth_rpc_url: &str,
network: Network,
verification_data: &[VerificationData],
wallet: Wallet<SigningKey>,
nonce: U256,
payment_service_addr: &str,
) -> Vec<Result<AlignedVerificationData, errors::SubmitError>>batcher_url- The url of the batcher to which the proof will be submitted.eth_rpc_url- The URL of the Ethereum RPC node.network- The network on which the verification will be done (devnet | holesky-stage | holesky)verification_data- A verification data array.max_fees- A max fee array.wallet- The wallet used to sign the proof. Should be using correct chain id. Seeget_chain_id.nonce- The nonce of the submitter address. Seeget_nonce_from_ethereum.payment_service_addr- The address of the batcher payment service contract.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.
Result<Vec<AlignedVerificationData>, SubmitError>- An aligned verification data array or an error.
MissingRequiredParameterif the verification data vector is empty.ProtocolVersionMismatchif the version of the SDK is lower than the expected one.UnexpectedBatcherResponseif the batcher doesn't respond with the expected message.SerializationErrorif there is an error deserializing the message sent from the batcher.WebSocketConnectionErrorif there is an error connecting to the batcher.WebSocketClosedUnexpectedlyErrorif the connection with the batcher is closed unexpectedly.EthereumProviderErrorif there is an error in the connection with the RPC provider.HexDecodingErrorif there is an error decoding the Aligned service manager contract address.BatchVerificationTimeoutif there is a timeout waiting for the batch verification.InvalidSignatureif the signature is invalid.InvalidNonceif the nonce is invalid.InvalidMaxFeeif the max fee is invalid.InvalidProofif the proof is invalid.ProofTooLargeif the proof is too large.InsufficientBalanceif the sender balance is not enough or unlockedProofQueueFlushedif there is an error in the batcher and the proof queue is flushed.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.GenericErrorif the error doesn't match any of the previous ones.
Checks if the proof has been verified with Aligned and is included in the batch on-chain.
pub async fn is_proof_verified(
aligned_verification_data: AlignedVerificationData,
network: Network,
eth_rpc_url: &str,
payment_service_addr: &str,
) -> Result<bool, errors::VerificationError>aligned_verification_data- The aligned verification data obtained when submitting the proofs.network- The network on which the verification will be done (devnet | holesky-stage | holesky)eth_rpc_url- The URL of the Ethereum RPC node.payment_service_addr- The address of the batcher payment service contract.
Result<bool, VerificationError>- A boolean indicating whether the proof was verified on-chain and is included in the batch or an error.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.HexDecodingErrorif there is an error decoding the Aligned service manager contract address.
Generates a keccak256 hash commitment of the verification key.
pub fn get_commitment(
content: &[u8]
) -> [u8; 32]content- A byte slice of the verification key.
[u8; 32]- A 32-byte array representing the keccak256 hash of the verification key.
Returns the nonce for a given address in Ethereum from aligned payment service contract.
Note that it might be out of sync if you recently sent proofs. For that see get_nonce_from_batcher
pub async fn get_nonce_from_ethereum(
eth_rpc_url: &str,
submitter_addr: Address,
network: Network,
) -> Result<U256, errors::NonceError>eth_rpc_url- The URL of the Ethereum RPC node.submitter_addr- The address of the proof submitter for which the nonce will be retrieved.network- The network on which the proof will be submitted
Result<U256, NonceError>- The nonce to use or an error.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.NotAContract(address)if you are trying to send to an address that is not a contract. This generally occurs if you have misconfigured theenvironmentparameter.
Returns the next nonce for a given address from the batcher.
You should prefer this method instead of get_nonce_from_ethereum if you have recently sent proofs,
as the batcher proofs might not yet be on ethereum, producing an out-of-sync nonce with the payment service contract on ethereum
pub async fn get_nonce_from_batcher(
batcher_ws_url: &str,
address: Address,
) -> Result<U256, GetNonceError> {batcher_url- The batcher websocket url.address- The user address for which the nonce will be retrieved.
Result<U256, NonceError>- The next nonce of the proof submitter account.
EthRpcErrorif the batcher has an error in the Ethereum call when retrieving the nonce if not already cached.
Returns the chain id for a given rpc url.
Should be used before submitting proofs to the batcher. Wallet chain id needs to be set with:
wallet = wallet.with_chain_id(chain_id);eth_rpc_url- The URL of the Ethereum RPC node.
Result<U256, ChainIdError>- The nonce to use or an error.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.
Estimates the fee the user would have to pay for submitting a proof to Aligned. Depending on the
priority the user wants to have in the batch, the estimate parameter can be set.
pub async fn estimate_fee(
eth_rpc_url: &str,
estimate: PriceEstimate,
) -> Result<U256, errors::MaxFeeEstimateError>eth_rpc_url- The URL of the Ethereum RPC node.estimate- The parameter to set the priority for the proof to be included in the batch. It can be one ofMin,DefaultorMax.
Result<U256, MaxFeeEstimateError>- the estimatedmax_feedepending on the batch inclusion preference of the user.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.
Computes max_fee for a proof based on the number of proofs in a batch (num_proofs_per_batch) and number of proofs (num_proofs) in that batch the user would pay for i.e (num_proofs / num_proofs_per_batch).
pub async fn compute_max_fee(
eth_rpc_url: &str,
num_proofs: usize,
num_proofs_per_batch: usize,
) -> Result<U256, errors::MaxFeeEstimateError>eth_rpc_url- The URL of the Ethereum RPC node.num_proofs- The number of proofs in a batch the user would pay for.num_proofs_per_batch- The number of proofs within a batch.
Result<U256, MaxFeeEstimateError>- The calculatedmax_feeas aU256.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.
Returns the fee_per_proof based on the current gas price for a batch compromised of num_proofs_per_batch i.e. (1 / num_proofs_per_batch).
pub async fn fee_per_proof(
eth_rpc_url: &str,
num_proofs_per_batch: usize,
) -> Result<U256, errors::MaxFeeEstimateError>eth_rpc_url- The URL of the users Ethereum RPC node.num_proofs_per_batch- The number of proofs within a batch.
Result<U256, MaxFeeEstimateError>- The fee per proof of a batch ofnum_proofs_per_batchproofs as aU256.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.
Funds the batcher payment service in name of the signer
pub async fn deposit_to_aligned(
amount: U256,
signer: SignerMiddleware<Provider<Http>, LocalWallet>,
network: Network,
) -> Result<ethers::types::TransactionReceipt, errors::PaymentError> {amount - The amount to be paid.
signer - The signer middleware of the payer.
network - The network on which the payment will be done.
The receipt of the payment transaction.
SendError if there is an error sending the transaction.
SubmitError if there is an error submitting the transaction.
PaymentFailed if the payment failed.
Queries a User's balance that was deposited in Aligned
pub async fn get_balance_in_aligned(
user: Address,
eth_rpc_url: &str,
network: Network,
) -> Result<U256, errors::BalanceError> {user - The address of the user.
eth_rpc_url - The URL of the Ethereum RPC node.
network - The network on which the balance will be checked.
Result<U256, errors::BalanceError>- The balance of the user in the payment service.
EthereumProviderErrorif there is an error in the connection with the RPC provider.EthereumCallErrorif there is an error in the Ethereum call.