Skip to main content

Overview

In some cases, you may want to deploy a custom agent contract. This allows for more customizability inside the agent contract, allows you to restrict your agent to certain actions, and is used for building Shade Agents that interact with just NEAR.


Creating the Contract

To create a custom agent contract, we recommend you fork the sandbox contract. This is the agent contract that's deployed under the hood when using the shade-agent-cli. For testing locally, you will need to maintain a separate similar contract that does not implement the agent registration flow; for this, you can follow the structure of the proxy contract.

Inside this contract, you will create your own functions. For building contracts on NEAR, see our smart contract docs. You can only develop agent contracts in Rust.

With the quickstart template, an agent can sign any transaction. You may want to limit your agent to only be able to sign transactions for a limited set of functions or actions. For this, we recommend building your transactions inside your agent contract with the omni-transaction-rs library. In such case, you should make the request_signature function private.

For developing Shade Agents that just interact with NEAR, you can remove the request_signature function. The agent will make function calls to the contract directly. Make sure that you restrict relevant functions to only be allowed to be called by the agent. If you want to interact with existing contracts on NEAR that do not implement agent registration, you can leverage cross contract calls.

How you compile the contract depends on your operating system.

For Linux, you can compile the contract directly with cargo near.

cargo near build non-reproducible-wasm

Deploying the Custom Contract

To deploy your agent with the custom contract, add the --wasm flag when using the Shade Agent CLI, specifying the path to your wasm file. Depending on the size of the wasm, you may require more NEAR to deploy the contract. This can be done using the --funding flag, followed by the amount of NEAR (100KB = 1 NEAR).

Here is an example:

shade-agent-cli --wasm contract/target/near/contract.wasm --funding 5

Interacting with Custom Contract

To call a function on your custom agent contract, use the agentCall function provided by the Shade Agent API. Please refer to the relevant docs for calling the contract in your desired language.