1

I am trying to call the Maker CDP Contract manager smart contract.

I want to get the information from this public mapping in the contract.

mapping (bytes32 => Cup) public cups

and should return a mapping:

    struct Cup {
        address  lad;      // CDP owner
        uint256  ink;      // Locked collateral (in SKR)
        uint256  art;      // Outstanding normalised debt (tax only)
        uint256  ire;      // Outstanding normalised debt
    }

Where bytes32 should be a bytes representation of the CDPId. They have a python implementation that passes a value to this mapping from a function that looks like this.

def int_to_bytes32(value: int) -> bytes:
    assert(isinstance(value, int))
    return value.to_bytes(32, byteorder='big'

I've tried this:

myContract.methods.cups(web3.utils.fromAscii("5")).call(
    function (err, res){
        console.log(res)
    }
)

However, I cannot figure out for my life how to pass the proper ID of say 5 to the bytes32 mapping and return the proper output. Everything returns with 0's even though I know that is incorrect.

Any help is appreciated.

1

try this web3.utils.numberToHex(number) or just a string like this '0x0000000000000000000000000000000000000000000000000000000000000005'

1

Web3.utils.numberToHex(13850).substring(2).padStart(64, '0')

This was ultimately the solution that worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.