[Ethereum] sendTransaction BigNumber Error: new BigNumber() not a number: [object Object]

bignumbersoliditytestrpctransactionstruffle

I am new to Solidity programming and writing smart contracts for one of the application. Here are my two contracts. I am using truffle and testrpc as tool. I am getting error consistently. Need guidance. I have seen earlier threads with similar subject lines but they dont help. I already tried changing the name of the function as well.

//Certificate.sol

contract Certificate {
    address private addressSelf;
    bytes32 private certName;

    function Certificate(bytes32 _certName) {
        addressSelf = msg.sender;  
        certName = _certName;
    }  
}

//Participant.sol

contract Participant {
    address private addressSelf;
    bytes32 private participantName;

    struct CertStruct {
        Certificate certificateData;
        bool isCertificate;
    }

    mapping (address => CertStruct) public certStructs;
    mapping (uint => address) public certIndex;
    uint public noOfCerts;

    function Participant(bytes32 _partName) {
        addressSelf = msg.sender;  // just set the self
        participantName = _partName;
        noOfCerts = 0;
    }

    function isCertGranted(address certAddress) public constant returns(bool) {
        return certStructs[certAddress].isCertificate;
    }

    function grantCertToParticipant(address certAddress, Certificate certificate) payable public returns (bool)
    {
        if(!isCertGranted(certAddress)) return false;

        CertStruct memory newCertStruct;
        newCertStruct.certificateData = certificate;
        newCertStruct.isCertificate = true;
        certStructs[certAddress] = newCertStruct;
        certIndex[noOfCerts] = certAddress;
        noOfCerts++;

        return true;
    }
}

//participant.js

var CertificateSol = artifacts.require("./Certificate.sol");

var ParticipantSol = artifacts.require("./Participant.sol");

contract('Participant', function() {

    it("should put certificate in the one participant", function() {

        var newCert;
        var newPart;

        return CertificateSol.new('CertName').then(function(newCertInstance) {
            newCert = newCertInstance;
        }

        return ParticipantSol.new('Name of Participant').then(function(newPartInstance) {
            newPart = newPartInstance;

        newPart.grantCertToParticipant.sendTransaction(newCert.address, newCert, { from : web3.eth.accounts[0], gas: 3000000 }).then(function(returnFlag){

            newPart.noOfCerts.call().then(function(certNumber){
              console.log('certNumber is ' + certNumber.toString(10));
          });
        }).catch(function(err){
          console.log('I am at grantCertToParticipant err ' + err);
        });

    });    
}

Best Answer

First, you don't need to explicitly send transaction, it's enough to call a method:

newPart.grantCertToParticipant(newCert.address, newCert, { from : web3.eth.accounts[0], gas: 3000000 })

Second, newCert it's a contract proxy object, so don't pass it to web3 call. It's enough just to send newCert.address. I will leave only address in method signature:

function grantCertToParticipant(address certAddress) payable public returns (bool)

this line unfortunately doesn't make much sense:

newCertStruct.certificateData = certificate; 

as you cannot store the whole contract but only reference in the form of an address so it's redundant.

Related Topic