truffle assignment question -
pragma solidity 0.8.6;
pragma abicoder v2;
// "SPDX-License-Identifier: <SPDX-License>" "SPDX-License-Identifier: UNLICENSED"
contract multiSigAssignment {
address[] public owners;
uint limit;
struct Transfer{
uint amount;
address payable receiver;
uint approvals;
bool hasBeenSent;
uint id;
}
event TransferRequestCreated(uint _id, uint _amount, address _initiator, address _receiver);
event ApprovalReceived(uint _id, uint _approvals, address _approver);
event TransferApproved(uint _id);
Transfer[] transferRequests;
mapping(address => mapping(uint => bool)) approvals;
//Should only allow people in the owners list to continue the execution.
modifier onlyOwners(){
bool owner = false;
for(uint i=0; i<owners.length;i++){
if(owners[i] == msg.sender){
owner = true;
}
}
require(owner == true);
_;
}
//Should initialize the owners list and the limit
constructor(address[] memory _owners, uint _limit) {
owners = _owners;
limit = _limit;
}
//Empty function
function deposit() public payable {}
//Create an instance of the Transfer struct and add it to the transferRequests array
function createTransfer(uint _amount, address payable _receiver) public onlyOwners {
emit TransferRequestCreated(transferRequests.length, _amount, msg.sender, _receiver);
transferRequests.push(
Transfer(_amount, _receiver, 0, false, transferRequests.length)
);
}
//Set your approval for one of the transfer requests.
//Need to update the Transfer object.
//Need to update the mapping to record the approval for the msg.sender.
//When the amount of approvals for a transfer has reached the limit, this function should send the transfer to the recipient.
//An owner should not be able to vote twice.
//An owner should not be able to vote on a tranfer request that has already been sent.
function approve(uint _id) public onlyOwners {
require(approvals[msg.sender][_id] == false);
require(transferRequests[_id].hasBeenSent == false);
approvals[msg.sender][_id] = true;
transferRequests[_id].approvals++;
emit ApprovalReceived(_id, transferRequests[_id].approvals, msg.sender);
if(transferRequests[_id].approvals >= limit){
transferRequests[_id].hasBeenSent = true;
transferRequests[_id].receiver.transfer(transferRequests[_id].amount);
emit TransferApproved(_id);
}
}
//Should return all transfer requests
function getTransferRequests() public view returns (Transfer[] memory){
return transferRequests;
}
}
Hi guys, regarding the truffle assignment - when i used the instance.deposit({value:1000)} - everything went smoothly, however I wanted to see what would happen if i created a transfer, so i did instance.createTransfer({value:500}, 0xe784A0aBE1DFAf65116b0eFA83dB4E59108E7524)
However this returned the following errorā¦ What seems to be the issue?
Uncaught:
Error: invalid BigNumber value (argument="value", value={"value":500}, code=INVALID_ARGUMENT, version=bignumber/5.0.8)
at evalmachine.<anonymous>:0:10
at sigintHandlersWrap (vm.js:274:12)
at Script.runInContext (vm.js:142:14)
at runScript (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:270:1)
at Console.interpret (/usr/local/lib/node_modules/truffle/build/webpack:/packages/core/lib/console.js:285:1)
at bound (domain.js:416:15)
at REPLServer.runBound [as eval] (domain.js:427:12)
at REPLServer.onLine (repl.js:819:10)
at REPLServer.emit (events.js:375:28)
at REPLServer.emit (domain.js:470:12)
at REPLServer.Interface._onLine (readline.js:364:10)
at REPLServer.Interface._line (readline.js:700:8)
at REPLServer.Interface._ttyWrite (readline.js:1045:14)
at REPLServer.self._ttyWrite (repl.js:912:9) {
reason: 'invalid BigNumber value',
code: 'INVALID_ARGUMENT',
argument: 'value',
value: { value: 500 },
hijackedStack: 'Error: invalid BigNumber value (argument="value", value={"value":500}, code=INVALID_ARGUMENT, version=bignumber/5.0.8)\n' +
' at lib_esm_Logger.makeError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/logger/lib.esm/index.js:166:1)\n' +
' at lib_esm_Logger.throwError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/logger/lib.esm/index.js:175:1)\n' +
' at lib_esm_Logger.throwArgumentError (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/logger/lib.esm/index.js:178:1)\n' +
' at Function.from (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/bignumber/lib.esm/bignumber.js:211:22)\n' +
' at NumberCoder.encode (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/abi/lib.esm/coders/number.js:13:17)\n' +
' at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/abi/lib.esm/coders/array.js:57:1\n' +
' at Array.forEach (<anonymous>)\n' +
' at pack (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/abi/lib.esm/coders/array.js:43:1)\n' +
' at TupleCoder.encode (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/abi/lib.esm/coders/tuple.js:19:16)\n' +
' at AbiCoder.encode (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/node_modules/@ethersproject/abi/lib.esm/abi-coder.js:82:1)\n' +
' at ABICoder.encodeParameters (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth-abi/lib/index.js:121:1)\n' +
' at /usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:439:1\n' +
' at Array.map (<anonymous>)\n' +
' at Object._encodeMethodABI (/usr/local/lib/node_modules/truffle/build/webpack:/node_modules/web3-eth/node_modules/web3-eth-contract/lib/index.js:438:6)\n' +
' at /usr/local/lib/node_modules/truffle/build/webpack:/packages/contract/lib/execute.js:182:1\n' +
' at runMicrotasks (<anonymous>)'