Install and set up
This page provides instructions to install and set up the MetaMask Delegation Toolkit. The toolkit consists of the following packages:
@codefi/delegator-core-viem
- A Viem client to use in any JavaScript or Node.js environment.
It also includes a suite of smart contracts available in the
@metamask/delegation-framework
package.
Prerequisites
- Install Node.js v18 or later.
- Install Yarn, npm, or another package manager.
- If you plan to use any smart contracts (for example, to create a custom caveat enforcer), install Foundry.
Steps
1. Get the authentication token
The MetaMask Delegation Toolkit is currently published to a private package registry. You can request access by contacting the MetaMask Delegation team, who will provide you with an authentication token.
2. Configure your package manager
Create a .yarnrc.yml
or .npmrc
file in the root of your project with the following content, and
replace <auth-token>
with the authentication token:
- Yarn
- npm
npmRegistries:
"https://nexus.eu-west-3.codefi.network/repository/npm-hosted/":
npmAuthToken: <auth-token>
npmScopes:
codefi:
npmRegistryServer: "https://nexus.eu-west-3.codefi.network/repository/npm-hosted/"
//nexus.eu-west-3.codefi.network/repository/npm-hosted/:_authToken=<auth-token>
@codefi:registry=https://nexus.eu-west-3.codefi.network/repository/npm-hosted/
If you're using an alternative package manager (such as pnpm or Bun), refer to its documentation.
3. Install the toolkit
Install the MetaMask Delegation Toolkit dependencies:
- Yarn
- npm
yarn add @codefi/delegator-core-viem
npm install @codefi/delegator-core-viem
4. (Optional) Install the contracts
If you plan to extend the Delegation Framework smart contracts (for example, to create a custom caveat enforcer), install the contract package using Foundry's command-line tool, Forge:
forge install metamask/delegation-framework
Add @metamask/delegation-framework/=lib/metamask/delegation-framework/
in your remappings.txt
file.
5. Get started
You're now ready to start using the MetaMask Delegation Toolkit. Check out the Viem client quickstart to walk through setting up a simple example.
You can see a complete example in the
hello-gator
repository.