Documentation for Getting Started with contract interactions within your app.
If you haven't already read through the Protocol and Contracts section you may find that helpful context before working through this section.
When building on the Intuition protocol there are offchain interactions (covered in the API section) and onchain interactions, which are covered in this section. The user journeys within our Portal app combine offchain and onchain interactions. Combining both of these types of flows are helpful to understand, even if you want to only integrate one type.
The examples and reference included in this section are included in our Remix Starter Template and are directly informed by how we use them in the Portal. Additionally, the examples used in our Starter (and covered in this section) can serve as a general guide for onchain interactions using Remix. You can follow the same patterns used and switch out the ABI and contract interactions at any point.
Manual Installation
This section includes general installation instructions if you choose to not directly clone or fork our Remix starter. If you're using our starter you can skip over this content.
Installation
You'll need to install wagmi and viem. Our starter currently uses npm but you should use whichever package manager you prefer.
We are currently using viem v1.x and haven't fully tested viem 2. x yet. Once we do, we'll update our starters and our docs.
npm install wagmi viem
yarn add wagmi viem
Environment Variables
You'll need to set the following environment variables in a .env . You can reference these in the Remix Starter Templates .env.example
.env
// include your values for theseALCHEMY_API_KEY=ALCHEMY_RPC_URL=WALLETCONNECT_PROJECT_ID=
Scaffolding the Interactions
The code examples used in this section are pulled from our Remix Starter Template. If you're building these interactions yourself outside of our starter, you can structure the files however you prefer.
Folder Conventions
Our starter and Portal use the following conventions:
lib folder contains abis, hooks , and utils folders
abis folder contains a viem compatible mapping of our EthMultiVault ABI
Name this file ethMultiVault.ts
You can include other ABIs in this same structure, or completely swap out our contract for another!
utils folder contains a constants.ts and a viem.ts configuration file
ConfigurationFiles
ethMultiVault.ts
exportconstmultivaultAbi= [{...}]
The key takeaway is that this needs to be a .ts file and exported as const for viem's type inference and ABI support.
Note: The actual ABI values are included inside the {...} in the above example.
This file is critical as it provides viem with the ABI (multiVaultAbi) , RPC information, and the MULTIVAULT_CONTRACT_ADDRESS from constants.ts
Be sure to include the export const multiVaultContract = {} as const. This is necessary for viem contract interactions.
You'll also need to check that ALCHEMY_RPC_URL and ALCHEMY_MAINNET_RPC_URL in your .env
useMultiVaultContract Hook
Each page in this section goes into more detail about specific hooks for specific contract interactions. This section includes an overview of our helper hooks for contract interactions. This is all included in our Remix Starter.
These hooks are included in /lib/hooks in our folder convention.
This hook provides scaffolding for using our contract interaction hooks
Note: You'll need to create a publicClient with wagmi's usePublicClient hook
Once you've created this hook you can then use it in the other contract interactions that call functions
Contract Reads
Once you've set up all of the configuration from the previous sections, you can use them for contract reads. The following example is Remix specific and is used in both our Portal app and our Remix Starter. You can generalize this for inclusion in a React framework of your choice.
We're using a Remix resources route with a loader to read from our contract and provide data to one of our Remix routes.
This example is Remix specific, but you can integrate the contract reads in however way you need for your use case.
Contract Writes
Once you've set up all of the configuration from the previous sections, you can use them for contract writes. The following example is used in both our Portal app and our Remix Starter. There are some Remix specific parts, but you can generalize this for inclusion in a React framework of your choice.
The next pages in this section will go deeper into specific interactions. Let's look at two hooks used in our scaffolding for contract writes.