Hello Everyone,
I’ve been having an issue with creating an instance of my Wallet contract from within the truffle develop environment. I have no issue with the line:
truffle(develop)> let link = await Link.deployed()
And once that’s set, I’m able to call functions with link.functionName().
BUT!, when I try to declare an instance of my Wallet contract:
truffle(develop)>let wallet = await Wallet.deployed()
I receive this reply:
Uncaught TypeError: Wallet.deployed is not a function
at evalmachine.<anonymous>:1:16
I suspect one of you savvy devs/fellow students can help me be more savvy too by helping me crack this case.
Below are my pertinent Migration files followed by the Link and Wallet contracts:
//filenae 2_wallet_migration.js
const Wallet = artifacts.require("Wallet");
module.exports = function (deployer) {
deployer.deploy(Wallet);
};
//filename 3_token_migration.js
const Link = artifacts.require("Link");
module.exports = function (deployer) {
deployer.deploy(Link);
};
Wallet Contract:
pragma solidity ^0.8.0;
import "../node_modules/@openzeppelin/contracts/token/erc20/IERC20.sol";
import "../node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../node_modules/@openzeppelin/contracts/access/Ownable.sol";
contract Wallet is Ownable{
using SafeMath for uint256;
struct Token{
bytes32 ticker;
address tokenAddress;
}
modifier tokenExists(bytes32 ticker){
require(tokenMapping[ticker].tokenAddress != address(0), "token does not exist");
_;
}
mapping(bytes32 => Token) public tokenMapping;
bytes32[] public tokenList;
mapping(address => mapping(bytes32 => uint256)) public balances;
event deposit_successful(address toAccount, bytes32 ticker, uint amount);
function addToken(bytes32 ticker, address tokenAddress) onlyOwner external{
tokenMapping[ticker] = Token(ticker, tokenAddress);
tokenList.push(ticker);
}
function deposit(uint amount, bytes32 ticker) tokenExists(ticker) external{
IERC20(tokenMapping[ticker].tokenAddress).transferFrom(msg.sender, address(this), amount);
balances[msg.sender][ticker] = balances[msg.sender][ticker].add(amount);
}
function withdraw(uint amount, bytes32 ticker) tokenExists(ticker) external{
require(balances[msg.sender][ticker] >= amount, "balance not sufficient");
balances[msg.sender][ticker] = balances[msg.sender][ticker].sub(amount);
IERC20(tokenMapping[ticker].tokenAddress).transfer(msg.sender, amount);
//calls the .transfer() function of the contract at the address
//given by TokenMapping...
}
}
Token Contract
pragma solidity ^0.8.0;
import "../node_modules/@openzeppelin/contracts/token/erc20/ERC20.sol";
contract Link is ERC20{
constructor() ERC20("Chainlink", "LINK") public{ //constructors assumed public or internal
_mint(msg.sender, 1000);
}
}
Thanks!
David