Skip to main content

Batching with Caller

Caller adds a number of powerful functionalities to Drips related to batching of function calls and delegation of access control. Specifically, it is also a smart contract included with the Drips V2 deployment that builds on EIP-712 and EIP-2771.

Some examples of use cases that Caller enables include:

Batching sequences of calls to a contract.

The contract API may consist of many functions which need to be called in sequence, but it may not offer a composite function performing exactly that sequence. It's expensive, slow and unreliable to create a separate transaction for each step. To solve that problem create a batch of calls and submit it to callBatched.

Batching sequences of calls to multiple contracts.

It's a common pattern to submit an ERC-2612 permit to approve a smart contract to spend the user's ERC-20 tokens before running that contract's logic. Unfortunately unless the contract's API accepts signed messages for the token it requires creating two separate transactions making it as inconvenient as a regular approval. The solution is again to use callBatched because it can call multiple contracts. Just create a batch first calling the ERC-20 contract and then the contract needing the tokens.

Setting up a proxy address.

Sometimes a secure but inconvenient-to-use address like a cold wallet or a multisig needs to have a proxy or an operator. That operator is temporarily trusted, but later it must be revoked or rotated. To achieve this, first authorize the proxy using the safe address and then use that proxy to act on behalf of the secure address using callAs. Later, when the proxy address needs to be revoked, either the secure address or the proxy itself can unauthorize the proxy address and perhaps authorize another address.

Setting up operations callable by others.

Some operations may benefit from being callable either by trusted addresses or by anybody. To achieve this deploy a smart contract executing these operations via callAs and, if you need that too, implementing a custom authorization. Finally, authorize this smart contract to act on behalf of your address.

Batching dynamic sequences of calls.

Some operations need to react dynamically to the state of the blockchain. For example an unknown amount of funds is retrieved from a smart contract, which then needs to be dynamically split and used for different purposes. To do this, first deploy a smart contract performing that logic. Next, call callBatched which first calls authorize on the Caller itself authorizing the new contract to perform callAs, then calls that contract and finally unauthorize's it. This way the contract can perform any logic it needs on behalf of your address, but only once.

Gasless transactions.

It's an increasingly common pattern to use smart contracts without necessarily spending Ether. This is achieved with gasless transactions where the wallet signs an ERC-712 message and somebody else submits the actual transaction executing what the message requests. It may be executed by another wallet or by an operator expecting to be repaid for the spent Ether in other assets. You can achieve this with callSigned, which allows anybody to execute a call on behalf of the signer of a message. Caller doesn't deal with gas, so if you're using a gasless network, it may require you to specify the gas needed for the entire call execution.

Executing batched calls with authorization or signature.

You can use both callAs and callSigned to call Caller itself, which in turn can execute batched calls on behalf of the authorizing or signing address. It also applies to authorize and unauthorize, they too can be called using callAs, callSigned or callBatched.

Using Caller Via the SDK

The Drips SDK includes a CallerClient class which makes it easy for developers to interact with the Caller smart contract to batch Drips method calls generated by their apps.

Using the SDK, you can create a CallerClient like this:


// Assuming you have your wallet connected you should have a `provider` instance.
callerClient = await CallerClient.create(provider)

Once you have a CallerClient instance, Drips method calls can be batched by calling the CallerClient.callBatched method. Take a look at this method's documentation to learn more about its use.

In this version of the SDK, only the batching-related functions of Caller are available. SDK support for Caller's authorization/delegation-related features may be added in a future version.