I successfully execute smart contract function in the truffle development console, for example:
let instance = await MetaCoin.deployed()
let accounts = await web3.eth.getAccounts()
instance.sendCoin(accounts[1], 10, {from: accounts[0]})
I get the "Coin" in my accounts[1]. But the problem is when I try to use python, it gives an error.
contractAddress = '0x...'
abi = '...'
contract = w3.eth.contract(contractAddress, abi=abi)
contract.functions.sendCoin(accounts[1], 10, {from: accounts[0]})
Error:
contract.functions.sendCoin(accounts[1], 10, {from: accounts[0]})
^
SyntaxError: invalid syntax
This is my sendCoin
function:
event Transfer(address indexed _from, address indexed _to, uint256 _value);
function sendCoin(address receiver, uint amount) public returns(bool sufficient) {
if (balances[msg.sender] < amount) return false;
balances[msg.sender] -= amount;
balances[receiver] += amount;
emit Transfer(msg.sender, receiver, amount);
return true;
}