Offchain and Onchain Protocol Flows
Beav3r protocol currently has two main flow families:
- offchain approval flow
- onchain authorization flow
Use the offchain flow when the SDK caller executes the final action itself.
Use the onchain flow when the final action must be executed by an onchain executor contract with a signed authorization artifact.
Package split (recommended)
- offchain client + approval routing:
@beav3r/sdk - shared protocol types/schemas:
@beav3r/protocol - onchain helper utilities (artifact/executor helpers):
@beav3r/protocol-onchain
Offchain flow (standard)
This is the default integration path:
- submit action with
guardorguardAndWait - Beav3r evaluates policy
- action is allowed, denied, or routed to signer approval
- caller handles the terminal result
Minimal offchain example:
TypeScript
import { Beav3r } from '@beav3r/sdk'
const client = new Beav3r({
baseUrl: 'https://staging.server.beav3r.ai',
apiKey: process.env.BEAV3R_API_KEY
})
const result = await client.guardAndWait(
{
actionType: 'payments.send_usdt',
payload: { amount: 25, recipient: '0x1111111111111111111111111111111111111111' }
},
{ pollIntervalMs: 2000, timeoutMs: 5 * 60 * 1000 }
)Onchain flow (authorization + executor)
Trusted executor model (core concept)
Provisioning an onchain actor returns:
account: the supplied actor identity, returned in the actor recordexecutor: the contract address to trust onchain
Target contracts grant permissions to the executor address. At execution time, the target contract sees msg.sender = executor.
The executor only runs calls with a valid Beav3r authorization artifact. Beav3r authorization controls which calls can execute through the trusted executor.
This path adds an authorization artifact step:
- submit action with
guardAndWait - after approval, call
authorizeOnchainAction - normalize artifact (
actionHash,keyId,signature) - call executor contract
executeWithAuth(...)onchain
Minimal onchain package usage:
npm install @beav3r/sdk@beta @beav3r/protocol-onchain viemTypical structure:
- calls
guardAndWait - calls
authorizeOnchainAction - normalizes
actionHash/keyId/signature - sends executor
executeWithAuth(...)onchain
Execution breakdown:
- executor receives target call + signed authorization payload
- executor verifies chain, executor address, account binding, expiry, and nonce replay
- executor asks verifier to validate signature trust against Beav3r signer registry
- if valid, executor performs
to.call(...)to target contract - target contract sees
msg.sender = executorand applies permissions accordingly
Direct SDK-level onchain example:
TypeScript
import { Beav3r } from '@beav3r/sdk'
const client = new Beav3r({
baseUrl: process.env.BEAV3R_BASE_URL,
apiKey: process.env.BEAV3R_API_KEY
})
const transferData = '0x...' // encoded ERC20 transfer calldata
await client.guardAndWait({
actionType: 'payments.send_usdt',
payload: { amount: '70', calldata: transferData, chainId: 84532 }
})
const auth = await client.authorizeOnchainAction({
projectId: process.env.BEAV3R_PROJECT_ID,
account: '0xActorAccount',
to: '0xTokenAddress',
value: '0',
data: transferData,
chainId: 84532,
nonce: Math.floor(Date.now() / 1000),
expiresAt: Math.floor(Date.now() / 1000) + 1200,
executor: '0xExecutorAddress'
})
// Use auth.item.artifact.payload + auth.item.artifact.signature
// to call executor.executeWithAuth(...) onchain.Choosing the path
- choose offchain when no onchain executor authorization is needed
- choose onchain when execution must be bound to a signed artifact and executor contract