Skip to content

Latest commit

 

History

History
61 lines (47 loc) · 3.4 KB

README.md

File metadata and controls

61 lines (47 loc) · 3.4 KB

Smart Accounts API

This project has the solidity contracts for smart accounts in hardhat/contracts/.
In here you will find the Account contract, which is an implementation of both ERC20Account and ERC721Account with Ownable so that only the user that created that smart account can call non-view methods on that smart account.
Additionally, there is an interface for IERC20Account and IERC721Account for the exposed methods from both account types. Finally, AccountFactory allows for Smart Accounts to be deployed diretly from a smart contract, and holds the addresses of all the smart accounts it has currently created.

Compiling and using

This repository already has the AccountFactory deployed on Alastria's Red B node.
You can find the address for this deployment in hardhat/addresses-redB.json.
You can chose to deploy on a different node or network if you wish, so if you do, please follow the instructions in hardhat/README.md for how to compile and deploy the contracts.
Additionally, I'll provide further instructions here to modify the API so that it uses the new deployment:

Once you have compiled the contracts and deployed the AccountFactory, grab first the ABIs for AccountFactory and Account and update api/contracts.json with the new ABIs.
After this, grab the address for the deployed AccountFactory from hardhat/addresses-NETWORK.json (where NETWORK is the network you deployed the smart contract to) and replace address in api/contracts.json for AccountFactory with that new address.
Once this is done, make sure to update the .env file in api/.env (if it doesn't exist, create it using .env-sample as a template) so that the api connects to the blockchain network you deployed the contract to.

And that's it, you can then start up the API either with docker or node and start using the endpoints.

Startup with node

npm i
npm start

Startup with docker

docker build . -t smart-accounts
docker run -d -p 3000:3000 smart-accounts

The endpoints exposed by the API at http://localhost:3000 can be used with Postman, or directly with some other program that can make HTTP requests.
We have included a postman collection in api/docs/Smart Accounts API.postman_collection.json which already has all the calls prepared.
You will just have to configure the variables for the collection to add the correct API Key for the collection in the current value field.
You can find the API key if you compile this locally in api/src/exposition/middleware/apiKey.middleware.ts, or if you are using a version we deployed, you will have to get the API key directly from us.

Running Tests

To run the tests, you need to configure the URL of the node, the private key, and ensure you have the ABI and bytecode for the contracts. api/src/_tests_/contract.service.test.ts

beforeAll(() => { logger = new Logger(); contracts = {}; // Add your contract collection here config = { NETWORK: { WALLET_PRIV_KEY: 'your-private-key', URL: 'http://localhost:8545' }

Install the necessary dependencies: Create a .env file in the api directory (if it doesn't exist) and add the following configuration: Update api/contracts.json with the ABI and bytecode of the AccountFactory and Account contracts.

Create the Jest configuration file jest.config.js in the api directory.

Run the tests:

npx jest