An ecommerce agent based on Ethereum. The business can collect any ERC-20 tokens through sell products , such as USDT, BAT and so on.
./scripts/dev_setup.sh
will install the following dependencies.
- Ally implemented in Golang.
- beanstalk is in charge of internal communication.
- Besides infura and Etherscan provide the Ethereum APIs. Please get the api keys from their platforms.
The Ethereum has one mainnet and some testnet. Also it has many token. Ally choose them through the operating system environment variables. Besides other configurations are set by this way. Please set the following environment variables before setup ally.
INFURA_ENDPOINT
the infura endpoint, default iskovan
INFURA_ID
the infura project ID from your dashboardETHERSCAN_HOST
the Etherscan host, default isapi-kovan.etherscan.io
ETHERSCAN_APIKEY
the Etherscan APIKEYTOKEN_CONTRACT
the token contract address, default is0xFab46E002BbF0b4509813474841E0716E6730136
CONTRACT_ADDRESS_FACTORY_ADDRESS
the contract address, get it after deploy the smart contract
$ ./scripts/start_api.sh
$ curl "http://localhost:8080/api/v1/admin/rootAddress"
Deploy the contracts under the contracts directory and get the contract address. Remember set it into the Environment.
$ ./scripts/deploy_contracts.sh
Don't forget start beanstalk
before this step.
- dispatcher
$ ./scripts/start_dispatcher.sh
- worker
$ ./scripts/start_worker.sh
- create a product
$ curl -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"externalID": "my_id", "price": "0.01"}' http://localhost:8080/api/v1/items
- create an order
$ curl -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"itemID": 1, "sequence": 1, "account": "test"}' http://localhost:8080/api/v1/orders
- get the deposit address and then deposit the exact tokens into the address
It maybe take a little time for confirmation. You can check the order's transaction status with the ethereum browser.
$ curl "http://localhost:8080/api/v1/orders/1"
- check the balance of Ally agent
$ curl "http://localhost:8080/api/v1/stat"
- withdraw tokens
$ curl -X POST -H "Content-type: application/json" -H "Accept: application/json" -d '{"to": "0xAdbf42299d432Db7A70e298d07B7f33ce84Ae095", "amount": "0.01"}' http://localhost:8080/api/v1/admin/withdraw
- check the status of withdraw
$ curl "http://localhost:8080/api/v1/transactiongroups/1"