Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/critesjosh/contract_spending_cusd
Simple app to demo how to use a contract to spend cUSD on a users behalf.
https://github.com/critesjosh/contract_spending_cusd
Last synced: 18 days ago
JSON representation
Simple app to demo how to use a contract to spend cUSD on a users behalf.
- Host: GitHub
- URL: https://github.com/critesjosh/contract_spending_cusd
- Owner: critesjosh
- License: apache-2.0
- Created: 2021-10-19T21:35:08.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2021-10-19T23:54:19.000Z (about 3 years ago)
- Last Synced: 2024-10-29T07:41:08.392Z (2 months ago)
- Language: JavaScript
- Size: 1.41 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Spending cUSD from another Solidity Contract
Simple app to demo how to use a contract to spend cUSD on a users behalf.
## Spending cUSD on behalf of users
This example demonstrates how a contract can be designed to spend cUSD for a user. View the simple contract in `./contracts/cUSD_spender.sol`. This contract is too simple to be useful, but demonstrates the necessary concepts, namely how to access the cUSD contract from another Solidity contract.
Before the cUSD_spender contract can spend cUSD on behalf of a user, the user must approve the contract to spend cUSD for them. The `./webpage` directory shows how you can do this. Essentially, in the UI the dapp will request a transaction from the user, to the cUSD contract, calling the `approve` function for the desired amount. Once the `approve` transaction is confirmed, the dapp can request to `send` cUSD from the user's account.
## Get Started
1. Run yarn install in the project root.
2. Run `node createAccount.js`. This will print new Celo account details. Copy the private key for your new account into the PRIVATE_KEY variable in .env.
3. Fund the account address on the Alfajores testnet here: https://celo.org/developers/faucet
4. Deploy your own cUSD_spender contract to the Alfajores testnet with `truffle migrate --network alfajores`
5. Move into the `./webage` directory. Run `yarn` to install the dependencies.
6. Run the web server with `yarn dev`.