i am new to blockchain and solidity.
im trying to understand the behaviour of the 'new' keyword in solidity.
I have a deployed contract Coin
and in the coin contract you have the ability to transfer value from one address to another.
once you create the contract it will reward the first user with some value.
I dont know how to call the getBalance()
from another contract. If i create a variable with new Coin()
, doesn't that mean i have created a brand new instance of Coin?
How do i call methods on a contract that is already deployed from another contract.
pragma solidity ^0.4.17;
contract Coin {
mapping (address => uint) balances;
function Coin() public {
balances[msg.sender] = 100;
}
function sendCoin(address receiver, uint amount) public returns (bool) {
require(balances[msg.sender] >= amount);
balances[msg.sender] -= amount;
balances[receiver] += amount;
return true;
}
function getBalance() public view returns (uint) {
return balances[msg.sender];
}
}