Skip to main content

Deploying the AI DAO

On this page we'll guide you through deploying your own instance of the AI DAO.


Prerequisites


  • First, clone the repo.

    git clone https://github.com/NearDeFi/shade-agent-template
    cd shade-agent-template
  • Rename the .env.development.local.example file name to .env.development.local and configure your environment variables.

  • Start up Docker:

    sudo systemctl start docker
  • Install dependencies

    npm i

Local Development

In this tutorial, the AI DAO uses a custom agent contract. Because of this, you need to manually switch the contract deployed depending on whether you're developing locally or deploying the agent to a TEE.

  • For local development, you need to comment out the require approved code hash line within the agent_vote function. This allows anyone to call the function, not just a registered agent. By design, it's impossible for an agent to register when running locally, as it can't provide a valid TEE attestation.

  • Since the AI DAO uses a custom agent contract, you need to compile it yourself.

    cargo near build non-reproducible-wasm
  • Make sure that the NEXT_PUBLIC_contractId prefix is set to ac-proxy. followed by your NEAR account ID so the CLI is configured for local deployment.

  • Run the Shade Agent CLI with the wasm and funding flags. The wasm flag tells the CLI the path to the wasm file of the agent contract you're deploying, and the funding flag tells the CLI how much NEAR to fund the deployment with. 7 NEAR is sufficient for the size of the DAO contract.

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

    The CLI may prompt you to enter your sudo password.


TEE Deployment

  • Re-introduce the require approved code hash line so it requires an agent to be registered, meaning it's running in a genuine TEE and executing the expected agent code.

  • Because the contract has changed since you last deployed it, you need to compile it again.

    cargo near build non-reproducible-wasm
  • Change the NEXT_PUBLIC_contractId prefix to ac-sandbox. followed by your NEAR account ID so the CLI is configured for TEE deployment.

  • Run the Shade Agent CLI with the wasm and funding flags.

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

    The CLI may prompt you to enter your sudo password.

    After deploying to Phala Cloud, monitor your deployments and delete unused ones to avoid unnecessary costs. You can manage your deployments from thedashboard.


Interacting with the AI DAO

  • Set the DAO manifesto in the contract. Since the NEAR_ACCOUNT_ID in your environment variables is automatically assigned the owner of the agent contract, you need to sign this transaction using its SEED_PHRASE.

    near contract call-function as-transaction YOUR_CONTRACT_ID set_manifesto json-args '{"manifesto_text": "This DAO only approves gaming-related proposals and rejects everything else"}' prepaid-gas '100.0 Tgas' attached-deposit '0 NEAR' sign-as YOUR_ACCOUNT_ID network-config testnet sign-with-seed-phrase 'YOUR_SEED_PHRASE' --seed-phrase-hd-path 'm/44'\''/397'\''/0'\''' send

    Make sure to replace YOUR_CONTRACT_ID, YOUR_ACCOUNT_ID, and YOUR_SEED_PHRASE with the appropriate values before executing the command. You can optionally change the manifesto_text as well.

  • Set your NEXT_PUBLIC_contractId in the frontend's config.js file.

  • Start the frontend

    cd frontend
    npm i
    npm run dev