Skip to main content

Callers

In the context of a transaction on a blockchain, the term caller refers to the subject or entity that performs the transaction or invokes a smart function on the blockchain smart contract.

When someone wants to interact with a smart contract, either to send a transaction or request information, they become the caller of the transaction. The caller can be an individual, an organization, or even another smart contract on the same or a different blockchain.

The caller provides the necessary parameters and the corresponding digital signature to authorize and validate the transaction. These parameters can include input data, such as numeric values or text strings, that are used in the execution of the smart contract.

The concept of a caller is important because it allows the source of a transaction or request to be traced on the blockchain. It also plays a role in managing permissions and access control in smart contracts, as the contract can perform checks to verify the identity or privileges of the caller before executing a specific function.

In summary, the caller in a transaction on the blockchain is the entity that initiates the interaction with a smart contract, providing the necessary data and the authorization to execute the desired transaction or function.

Utility CallerUtil

The sdk provides a utility called CallerUtil within the transaction module. This utility allows us to obtain a caller that will be used to sign the transactions.

const caller = sdk.transactions.callers.getCaller();

The way in which the caller is obtained in local or server mode are different. In local mode it is obtained from the user's connected wallet, while in server mode it is obtained from the key map sent as configuration when initializing the sdk.

Get the caller in server mode

When initializing the sdk we send a key-value map with the Ethereum addresses that will be used as the callers in each transaction.

A single caller

const wallets = new Map<string, string>();
const myWalletAddress = '0xa73a3b8ACa335855EeaC2f9Fb505BB0360A1B703';

wallets.set('default', myWalletAddress);

// After initializing the sdk

const caller = sdk.transactions.callers.getCaller(); //0xa73a3b8ACa335855EeaC2f9Fb505BB0360A1B703
Default caller

It is not necessary when getting the caller to specify the name default, since it checks if only one exists; then this will be returned.

Multiple callers

In this example, the address 0xa73a3b8ACa335855EeaC2f9Fb505BB0360A1B703 is the one that will be used as the caller in all transactions. The name default is the name of the caller and is used to identify it in the keymap. If our keymap has more than one caller, we can get them using the corresponding name.

const user1 = ['John', '0xa73a3b8ACa335855EeaC2f9Fb505BB0360A1B703'];
const user2 = ['Peter', '0xa73a3b8ACa335855EeaC2f9Fb506BB0360A1B702'];
const user3 = ['Lucas', '0xa73a3b8ACa335855EeaC2f1Fb505BB0360A1C603'];

const wallets = new Map<string, string>([user1, user2, user3]);


// After initializing the sdk

const caller1 = sdk.transactions.callers.getCaller('John'); //0xa73a3b8ACa335855EeaC2f9Fb505BB0360A1B703

const caller2 = sdk.transactions.callers.getCaller('Peter'); //0xa73a3b8ACa335855EeaC2f9Fb506BB0360A1B702

const caller3 = sdk.transactions.callers.getCaller('Lucas'); //0xa73a3b8ACa335855EeaC2f1Fb505BB0360A1C603