All users in Kinto are forced to interact with contracts by sending UserOps through the Kinto EntryPoint. In this guide we will learn to create and send UserOps.
As a developer, you can also interact with your contracts using the EOAs you list when creating the Kinto Application.
1. Preparing your Kinto Wallet for local testing
In order to use this guide you will need to configure your Kinto Wallet with a signing policy of 1/2 and add an EOA or hardware wallet as your second signer that you can use to sign locally.
In the Kinto website, click on the top right and select My Account -> Setup and follow the steps to add/change a signer and update your policy accordingly:
2. Creating and sending UserOps
Full example code is provided with ample comments.
contract KintoIncrementTest is MigrationHelper {
//Migration helper contains useful functions to interact with the Kinto chain
//Grab your signer private key, kinto wallet and counter deployed in previous guides
uint256 walletSignerKey = vm.envUint("KINTO_WALLET_SIGNER_KEY");
address kintoWalletAddress = vm.envAddress("KINTO_WALLET");
Counter counter = Counter(0xyourAddressHere);
console.log("Before UserOp. Counter:", counter.count());
//Setup kinto wallet
IKintoWallet _kintoWallet;
_kintoWallet = IKintoWallet(kintoWalletAddress);
uint256 nonce = _kintoWallet.getNonce();
//Setup signers for the kinto wallet
uint256[] memory privateKeys = new uint256[](1);
privateKeys[0] = walletSignerKey;
//Create a userOp array
UserOperation[] memory userOps = new UserOperation[](2);
// whitelist counter contract in the wallet
address[] memory targets = new address[](1);
targets[0] = address(counter);
bool[] memory flags = new bool[](1);
flags[0] = true;
//First userOp will whitelist the application
userOps[0] = _createUserOperation(
block.chainid,
address(_kintoWallet),
address(_kintoWallet),
0,
nonce,
privateKeys,
abi.encodeWithSignature("whitelistApp(address[],bool[])", targets, flags),
address(paymaster)
);
// increment counter
userOps[1] = _createUserOperation(
block.chainid,
address(_kintoWallet),
address(counter),
0,
nonce + 1,
privateKeys,
abi.encodeWithSignature("increment()"),
address(paymaster)
);
vm.broadcast(walletSignerKey);
entryPoint.handleOps(userOps, payable(walletSignerKey));
}