I'm following a guide that uses some web3 code written 3 years ago.
I am trying to use the TimeLockedWallet.info() call to get information about a wallet.
Below are my two smart contracts.
TimeLockedWalletFactory.sol
pragma solidity ^0.4.18;
import "./TimeLockedWallet.sol";
contract TimeLockedWalletFactory {
mapping(address => address[]) wallets;
function getWallets(address _user)
public
view
returns(address[])
{
return wallets[_user];
}
function newTimeLockedWallet(uint256 _unlockDate)
payable
public
returns(address wallet)
{
// Create new wallet.
wallet = new TimeLockedWallet(msg.sender, _unlockDate);
// Add wallet to sender's wallets.
wallets[msg.sender].push(wallet);
// Send ether from this transaction to the created contract.
wallet.transfer(msg.value);
// Emit event.
Created(wallet, msg.sender, now, _unlockDate, msg.value);
}
// Prevents accidental sending of ether to the factory
function () public {
revert();
}
event Created(address wallet, address to, uint256 createdAt, uint256 unlockDate, uint256 amount);
}
TimeLockedWallet.sol
pragma solidity ^0.4.18;
contract TimeLockedWallet {
address public owner;
uint256 public unlockDate;
uint256 public createdAt;
modifier onlyOwner {
require(msg.sender == owner);
_;
}
function TimeLockedWallet(address _owner, uint256 _unlockDate) public {
owner = _owner;
unlockDate = _unlockDate;
createdAt = now;
}
// keep all the ether sent to this address
function() public payable {
Received(msg.sender, msg.value);
}
// callable by owner only, after specified time
function withdraw() public onlyOwner {
require(now >= unlockDate);
//now send all the balance
msg.sender.transfer(this.balance);
Withdrew(msg.sender, this.balance);
}
function info()
public
view
returns (
uint256,
uint256,
uint256
)
{
return (unlockDate, createdAt, this.balance);
}
event Received(address from, uint256 amount);
event Withdrew(address to, uint256 amount);
event WithdrewTokens(address tokenContract, address to, uint256 amount);
}
And my frontend code tries to get information about the wallet from TimeLockedWallet.sol (unlockDate, owner, createdAt) using the contract.at()
function. However, I get an error
VM3368:1 Uncaught TypeError: c_timeLockedWallet.at is not a function
App.js
import TimeLockedWallet from "./contracts/TimeLockedWallet.json";
import TimeLockedWalletFactory from "./contracts/TimeLockedWalletFactory.json";
const c_timeLockedWalletFactory = new web3.eth.Contract(
TimeLockedWalletFactory.abi,
deployedNetwork && deployedNetwork.address,
);
const c_timeLockedWallet = new web3.eth.Contract(
TimeLockedWallet.abi,
);
const accounts = await web3.eth.getAccounts();
await c_timeLockedWalletFactory.methods.newTimeLockedWallet(unixTime).send({ from: accounts[0], value: web3.utils.toWei("1", "ether") });
const wallets = await c_timeLockedWalletFactory.methods.getWallets(accounts[0]).call();
c_timeLockedWallet.at(wallets[0]).then(function(walletInstance){return walletInstance.info();}).then(function(info){console.log(info)})
Is there another method to use to make this call? I've tried reading the web3 docs, but have come up short.