benediamond / anonymous-zether

A private payment system for Ethereum-based blockchains, with no trusted setup.
Other
16 stars 9 forks source link

deposit error #5

Closed jpitpol closed 3 years ago

jpitpol commented 3 years ago

Following the Readme file, i have deployed the zsc contract and initialised web3 First, in truffle i migrate and then in node i insert the following commands:

__dirname = '[full path to project folder]/anonymous-zether/packages/protocol';
const Client = require(path.join(__dirname, '../anonymous.js/src/client.js'));
Web3 = require('web3');
web3 = new Web3('http://localhost:9545');
contract = require("@truffle/contract");
path = require('path');
deployedJSON  = require(path.join(__dirname, 'build/contracts/ZSC.json'));
var provider = new Web3.providers.WebsocketProvider("ws://localhost:9545");
var deployed = contract(deployedJSON);
deployed.setProvider(provider);
deployed.deployed();
web3.eth.getAccounts().then(function(result) { accounts = result;});
var home;
web3.eth.getAccounts().then((accounts) => { home = accounts[accounts.length - 1];});
deployed.at(deployed.address).then(function(result) {dbg = result});
var alice = new Client(web3,dbg.contract,home)

After these, i follow the command of client.deposit() with the following error:

> alice.deposit(100)
Initiating deposit.
Promise { <pending> }
>
> Deposit failed: Error: Returned error: VM Exception while processing transaction: revert ERC20: transfer amount exceeds balance
(node:19916) UnhandledPromiseRejectionWarning: Error: Returned error: VM Exception while processing transaction: revert ERC20: transfer amount exceeds balance
    at Object.ErrorResponse (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\@truffle\interface-adapter\node_modules\web3-core-helpers\src\errors.js:29:16)
    at Object.callback (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\@truffle\interface-adapter\node_modules\web3-core-requestmanager\src\index.js:170:36)
    at C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\web3-providers-ws\lib\index.js:114:45
    at Array.forEach (<anonymous>)
    at WebsocketProvider._onMessage (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\web3-providers-ws\lib\index.js:102:69)
    at W3CWebSocket._dispatchEvent [as dispatchEvent] (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\yaeti\lib\EventTarget.js:115:12)
    at W3CWebSocket.onMessage (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\websocket\lib\W3CWebSocket.js:234:14)
    at WebSocketConnection.<anonymous> (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\websocket\lib\W3CWebSocket.js:205:19)
    at WebSocketConnection.emit (events.js:210:5)
    at WebSocketConnection.EventEmitter.emit (domain.js:498:23)
    at WebSocketConnection.processFrame (C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\websocket\lib\WebSocketConnection.js:554:26)
    at C:\Users\jsm.DESKTOP-7VJ0LVK\Desktop\anonymous-zether\packages\protocol\node_modules\websocket\lib\WebSocketConnection.js:323:40
    at processTicksAndRejections (internal/process/task_queues.js:75:11)
(node:19916) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 8)
benediamond commented 3 years ago

i think the error message is obvious here. you don't have enough ERC20 funds to cover the deposit you are trying to make. you need to mint yourself some funds.

jpitpol commented 3 years ago

on the read.me file you dont specify minting. How do i should mint in node?

jpitpol commented 3 years ago

These commands fixed the issue

cash.mint(home, 150, {from: home}).then(console.log)
cash.approve(dbg.address, 150, {from: home}).then(console.log)
cash.balanceOf.call(home).then(function(result) {balance = result});
assert.equal(balance, 150, "Minting failed");

im publishing them for future problems by other non-professionals