Ethcode latest update
Now you can debug any transaction of Ethereum network (including main and test networks)
Anyone minds me creating a grant benefiting Vyper?
https://gitcoin.co/grants/453/curve-related-vyper-research?tab=description
Can someone please help me understand what I'm doing wrong when trying to get the DAI balance of a Kovan address? I'm passing the Kovan DAI contract address at 0xb14A484B3D85Ff97E8d06CcA88a2d0aabE63CBb5 as _dai_address into my Vyper contract constructor and then calling setDaiBalance() from the address 0xb14A484B3D85Ff97E8d06CcA88a2d0aabE63CBb5, which is an address that has 50 Kovan DAI. But whenever I call getDaiBalance() I get 0!
Here's my code:
contract ERC20m:
def balanceOf(contractAddress: address) -> uint256: modifying
daitoken: ERC20m
daiBalance: uint256
daiAddress: address
def __init__(_dai: address,):
self.daiAddress = _dai
self.daitoken = ERC20m(_dai)
@public
def setDaiBalance(_amount: uint256):
self.daiBalance = self.daitoken.balanceOf(msg.sender)
@public
@constant
def getDaiBalance() -> uint256:
return self.daiBalance
0xb14A....CBb5 is both the Dai address and the address of the token holder you're interested in, are you sure those are both the right addresses to use?
Hey @fubuloubu !
I originally had balanceOf()as a constant and only changed it to modifying in an attempt to store the returned value for debugging. I'll change it back!
Oops sorry that was a typo. I'm using 0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa as the address of the Kovan DAI contract which I got from here https://github.com/makerdao/developerguides/tree/master/remittance and 0xb14A484B3D85Ff97E8d06CcA88a2d0aabE63CBb5 is a Kovan address that I created for testing which should have 50 DAI as shown here in the "Token" dropdown https://kovan.etherscan.io/address/0xb14A484B3D85Ff97E8d06CcA88a2d0aabE63CBb5. So 0x4f96....a6aa is _dai and 0xb14A....CBb5 is msg.sender in the code above, my bad.
const getDaiBalance = async ( params ) => {
// destructure the address of the deployed contract
const { contractAddress } = params;
// get a handle to the contract
let contractInstance = new web3.eth.Contract( contractJson['abi'], contractAddress );
// call getBalance()
const result = await contractInstance.methods.getDaiBalance().call();
// log the result and return it
console.log( 'RESULT: ', result );
return result
}
Interesting, I really appreciate the response, it sounds like I made the problem worse when trying to debug it!
All I'm trying to do is assert that a person calling makeOrder() on my contract actually has the _amount of DAI that they're trying to lock into the contract. I'm attempting (but failing) to do this by setting up a handle to the DAI contract in the constructor then calling DAI contract methods (like balanceOf() and transfer()) in other places inside of my contract. The issue is with the assert inside of makeOrder() because I'm always getting 0 as self.daitoken.balanceOf(msg.sender)
contract ERC20m:
def balanceOf(contractAddress: address) -> uint256: constant
def transfer(_to: address, _value: uint256) -> bool: modifying
PRECISION: constant(uint256) = 10 ** 18
daitoken: ERC20m
daiBalance: uint256
daiAddress: address
def __init__(_dai_address: address,):
self.daiAddress = _dai_address
self.daitoken = ERC20m(_dai_address)
@public
def makeOrder(_amount: uint256):
# THIS IS THE PROBLEM LINE, balanceOf returns 0!
assert self.daitoken.balanceOf(msg.sender) >= _amount / PRECISION
# this line never executes
self.daitoken.transfer(self, _amount)
50 * 10**18 instead
assert line is failing because self.daitoken.balanceOf(msg.sender) is returning 0, but I can't figure out why!
0xb14A484B3D85Ff97E8d06CcA88a2d0aabE63CBb5 and that address has 50 DAI as shown here: https://kovan.etherscan.io/token/0xc4375b7de8af5a38a93548eb8453a498222c4ff2?a=0xb14A484B3D85Ff97E8d06CcA88a2d0aabE63CBb5
0xC4375B7De8af5a38a93548eb8453a498222C4fF2 NOT the contract at 0x4f96fe3b7a6cf9725f59d353f723c1bdb64ca6aa which is the contract address listed in their docs. I swapped out the address listed in the docs for the address listed on Etherscan and the call worked as expected. I really appreciate all of the responses @fubuloubu, thanks so much!