Unable to call constant solidity functions from ethers.js
I have a trivial solidity contract and tried to call the constant getBalance function from ether.js - see below for the code. contract Trivial { function Trivial() public { } function getBalance () public constant returns ( uint8 ) { return 42 ; } }
This results in an error message:
Error: Error: invalid uint8
at throwError (/home/michael/blockchain/trivial/node_modules/ethers/utils/throw-error.js:4:17)
at Object.decode (/home/michael/blockchain/trivial/node_modules/ethers/utils/abi-coder.js:73:46)
at /home/michael/blockchain/trivial/node_modules/ethers/utils/abi-coder.js:292:32
at Array.forEach (
and I get the same error regardless of the type returned by getBalance. I see the same behavior in both quorum and a vanilla ethereum local blockchain and I can verify that the contract has already been mined. When I remove the constant qualifier from this error does not occur and ethers.js treats this as a "set" method returning a transaction response rather than the number 42. So the only way to move data from solidity to node.js using ether.js would appear to be be via events.
The relevant potion of the code that deploys a contract and calls getBalance is -
ethers.Wallet.fromEncryptedWallet( keyStore , password ).then ( async wallet => { wallet.provider = provider ; // Deploy new contract let contract = await ethers.Contract.getDeployTransaction ( byteCode, JSON.parse ( compile.interface ) ) ; let request = await wallet.sendTransaction ( contract ) ; let response = await request.wait() ; // Balance test let example = await new ethers.Contract ( response.creates , JSON.parse ( compile.interface ) , wallet ) ; let balance = await example.getBalance() ; } ).catch ( error => console.log ( "Error: " , error ) ) ;
The tx.creates does not currently work with Ganache due to a bug I've opened up a PR against them for.
For other networks, I have tracked down what I think may be a problem. I'm currently adding support for large chain ID's, which I think may fix this as well. I haven't been able to exactly replicate your error (I've replicated a slightly different one), but I will get this chain ID complete and see if that helps.
I changed my chainId to 87 so it fits in uint8, so I wouldn't think that it would be related to the current problem. What is the "slightly different" problem you replicated?
From: Richard Moore [email protected] Sent: Thursday, April 12, 2018 5:21 PM To: ethers-io/ethers.js Cc: michaelerose; Author Subject: Re: [ethers-io/ethers.js] Unable to call constant solidity functions from ethers.js (#161)
The tx.creates does not currently work with Ganache due to a bug I've opened up a PR against them for.
For other networks, I have tracked down what I think may be a problem. I'm currently adding support for large chain ID's, which I think may fix this as well. I haven't been able to exactly replicate your error (I've replicated a slightly different one), but I will get this chain ID complete and see if that helps.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ethers-io/ethers.js/issues/161#issuecomment-380948230, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADAl4R7RIy3T1vFjrS2Tv_uZwfNhqYavks5tn8VEgaJpZM4TSZ3F.
I just fixed the chain ID on my local version, and indeed, that doesn’t replicate your error. I am able to call the constant function successfully.
Still trying to reproduce the issue.
Can you print out the transaction you get from “response” and paste he output here?
Attached all relevant code and output .... the "response" output is:
{ hash: '0xf19c4905a57cf652226cf9da2ecc8407e2ba1ee5363a8b756c02a52706f71b5a', blockHash: '0x94a42cb9dfb5487bf08dfa6ed7ebbe1ba9e77d11c533a14010b1573539bb48ee', blockNumber: 4133, transactionIndex: 0, from: '0x7B7213e2343ee0257daDEb233D453DF62CBF2610', gasPrice: BigNumber { _bn: <BN: 430e23400> }, gasLimit: BigNumber { _bn: <BN: 16e360> }, to: null, value: BigNumber { _bn: <BN: 0> }, nonce: 33, data: '0x060006000600040005020304010506010000000005070600000008000000050006000001080006010000010006000000030906000000000300000600060006000400050206000004030601000600040805070603000000000000000007000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000030500040106060301020006050000000801010406000400050708000603060404040400000401040600070305070500060000000800000005000304010506000507050706000000080000000500060005000600080505060500060004000501060000000900090101060801050206000200000106000400050108000901000309000003050003040105060007000507060000000800000005000600080306000800050605000000050006000200090005060500070003030004000005000000000706050600010001000002000009000802000806000600000007080508030009050000090003080700070000000009040708030807060002000600040005010600000009010900090100000801050206000200000106000400050108000901000309000001050600000001060506020700070007020300050802000100000002080701000600000001000804000409000200000909000900030702020800000707020000000801000100000402000101000100000908030000090100000209', r: '0xd01001fe98de6bf1902aaedd819973c86cea9a435e263ff8fc15bc3a6200c055', s: '0x7278748cdb74741fc42eddb3021cc6ebd6993d992ce433943870f0df791e1b02', v: 210, creates: '0xD2C190842db99212C3d918Ff75370D58d3846698', raw: '0xf9027021850430e234008316e3608080b9021c06000600060004000502030401050601000000000507060000000800000005000600000108000601000001000600000003090600000000030000060006000600040005020600000403060100060004080507060300000000000000000700000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000003050004010606030102000605000000080101040600040005070800060306040404040000040104060007030507050006000000080000000500030401050600050705070600000008000000050006000500060008050506050006000400050106000000090009010106080105020600020000010600040005010800090100030900000305000304010506000700050706000000080000000500060008030600080005060500000005000600020009000506050007000303000400000500000000070605060001000100000200000900080200080600060000000708050803000905000009000308070007000000000904070803080706000200060004000501060000000901090009010000080105020600020000010600040005010800090100030900000105060000000106050602070007000702030005080200010000000208070100060000000100080400040900020000090900090003070202080000070702000000080100010000040200010100010000090803000009010000020981d2a0d01001fe98de6bf1902aaedd819973c86cea9a435e263ff8fc15bc3a6200c055a07278748cdb74741fc42eddb3021cc6ebd6993d992ce433943870f0df791e1b02', networkId: 87 }
From: Richard Moore [email protected] Sent: Thursday, April 12, 2018 5:47 PM To: ethers-io/ethers.js Cc: michaelerose; Author Subject: Re: [ethers-io/ethers.js] Unable to call constant solidity functions from ethers.js (#161)
I just fixed the chain ID on my local version, and indeed, that doesn’t replicate your error. I am able to call the constant function successfully.
Still trying to reproduce the issue.
Can you print out the transaction you get from “response” and paste he output here?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ethers-io/ethers.js/issues/161#issuecomment-380954456, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADAl4W3j4R_U1CB1WM2Ul39_Fy_cUCqUks5tn8t2gaJpZM4TSZ3F.
compile {
"assembly": {
".code": [
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "60"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "40"
},
{
"begin": 26,
"end": 295,
"name": "MSTORE"
},
{
"begin": 49,
"end": 82,
"name": "CALLVALUE"
},
{
"begin": 49,
"end": 82,
"name": "ISZERO"
},
{
"begin": 49,
"end": 82,
"name": "PUSH [tag]",
"value": "1"
},
{
"begin": 49,
"end": 82,
"name": "JUMPI"
},
{
"begin": 49,
"end": 82,
"name": "PUSH",
"value": "0"
},
{
"begin": 49,
"end": 82,
"name": "DUP1"
},
{
"begin": 49,
"end": 82,
"name": "REVERT"
},
{
"begin": 49,
"end": 82,
"name": "tag",
"value": "1"
},
{
"begin": 49,
"end": 82,
"name": "JUMPDEST"
},
{
"begin": 26,
"end": 295,
"name": "PUSH #[$]",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 26,
"end": 295,
"name": "DUP1"
},
{
"begin": 26,
"end": 295,
"name": "PUSH [$]",
"value": "0000000000000000000000000000000000000000000000000000000000000000"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "0"
},
{
"begin": 26,
"end": 295,
"name": "CODECOPY"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "0"
},
{
"begin": 26,
"end": 295,
"name": "RETURN"
}
],
".data": {
"0": {
".auxdata": "a165627a7a723058201dca2871e6fcc1b84c49b2bd9909e37228b077200c81c1af42b11a10d983ff910029",
".code": [
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "60"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "40"
},
{
"begin": 26,
"end": 295,
"name": "MSTORE"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "4"
},
{
"begin": 26,
"end": 295,
"name": "CALLDATASIZE"
},
{
"begin": 26,
"end": 295,
"name": "LT"
},
{
"begin": 26,
"end": 295,
"name": "PUSH [tag]",
"value": "1"
},
{
"begin": 26,
"end": 295,
"name": "JUMPI"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "FFFFFFFF"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "100000000000000000000000000000000000000000000000000000000"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "0"
},
{
"begin": 26,
"end": 295,
"name": "CALLDATALOAD"
},
{
"begin": 26,
"end": 295,
"name": "DIV"
},
{
"begin": 26,
"end": 295,
"name": "AND"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "12065FE0"
},
{
"begin": 26,
"end": 295,
"name": "DUP2"
},
{
"begin": 26,
"end": 295,
"name": "EQ"
},
{
"begin": 26,
"end": 295,
"name": "PUSH [tag]",
"value": "2"
},
{
"begin": 26,
"end": 295,
"name": "JUMPI"
},
{
"begin": 26,
"end": 295,
"name": "DUP1"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "64444DD4"
},
{
"begin": 26,
"end": 295,
"name": "EQ"
},
{
"begin": 26,
"end": 295,
"name": "PUSH [tag]",
"value": "3"
},
{
"begin": 26,
"end": 295,
"name": "JUMPI"
},
{
"begin": 26,
"end": 295,
"name": "tag",
"value": "1"
},
{
"begin": 26,
"end": 295,
"name": "JUMPDEST"
},
{
"begin": 26,
"end": 295,
"name": "PUSH",
"value": "0"
},
{
"begin": 26,
"end": 295,
"name": "DUP1"
},
{
"begin": 26,
"end": 295,
"name": "REVERT"
},
{
"begin": 88,
"end": 173,
"name": "tag",
"value": "2"
},
{
"begin": 88,
"end": 173,
"name": "JUMPDEST"
},
{
"begin": 88,
"end": 173,
"name": "CALLVALUE"
},
{
"begin": 88,
"end": 173,
"name": "ISZERO"
},
{
"begin": 88,
"end": 173,
"name": "PUSH [tag]",
"value": "4"
},
{
"begin": 88,
"end": 173,
"name": "JUMPI"
},
{
"begin": 88,
"end": 173,
"name": "PUSH",
"value": "0"
},
{
"begin": 88,
"end": 173,
"name": "DUP1"
},
{
"begin": 88,
"end": 173,
"name": "REVERT"
},
{
"begin": 88,
"end": 173,
"name": "tag",
"value": "4"
},
{
"begin": 88,
"end": 173,
"name": "JUMPDEST"
},
{
"begin": 88,
"end": 173,
"name": "PUSH [tag]",
"value": "5"
},
{
"begin": 88,
"end": 173,
"name": "PUSH [tag]",
"value": "6"
},
{
"begin": 88,
"end": 173,
"name": "JUMP"
},
{
"begin": 88,
"end": 173,
"name": "tag",
"value": "5"
},
{
"begin": 88,
"end": 173,
"name": "JUMPDEST"
},
{
"begin": 88,
"end": 173,
"name": "PUSH",
"value": "40"
},
{
"begin": 88,
"end": 173,
"name": "MLOAD"
},
{
"begin": 88,
"end": 173,
"name": "PUSH",
"value": "FF"
},
{
"begin": 88,
"end": 173,
"name": "SWAP1"
},
{
"begin": 88,
"end": 173,
"name": "SWAP2"
},
{
"begin": 88,
"end": 173,
"name": "AND"
},
{
"begin": 88,
"end": 173,
"name": "DUP2"
},
{
"begin": 88,
"end": 173,
"name": "MSTORE"
},
{
"begin": 88,
"end": 173,
"name": "PUSH",
"value": "20"
},
{
"begin": 88,
"end": 173,
"name": "ADD"
},
{
"begin": 88,
"end": 173,
"name": "PUSH",
"value": "40"
},
{
"begin": 88,
"end": 173,
"name": "MLOAD"
},
{
"begin": 88,
"end": 173,
"name": "DUP1"
},
{
"begin": 88,
"end": 173,
"name": "SWAP2"
},
{
"begin": 88,
"end": 173,
"name": "SUB"
},
{
"begin": 88,
"end": 173,
"name": "SWAP1"
},
{
"begin": 88,
"end": 173,
"name": "RETURN"
},
{
"begin": 218,
"end": 293,
"name": "tag",
"value": "3"
},
{
"begin": 218,
"end": 293,
"name": "JUMPDEST"
},
{
"begin": 218,
"end": 293,
"name": "CALLVALUE"
},
{
"begin": 218,
"end": 293,
"name": "ISZERO"
},
{
"begin": 218,
"end": 293,
"name": "PUSH [tag]",
"value": "7"
},
{
"begin": 218,
"end": 293,
"name": "JUMPI"
},
{
"begin": 218,
"end": 293,
"name": "PUSH",
"value": "0"
},
{
"begin": 218,
"end": 293,
"name": "DUP1"
},
{
"begin": 218,
"end": 293,
"name": "REVERT"
},
{
"begin": 218,
"end": 293,
"name": "tag",
"value": "7"
},
{
"begin": 218,
"end": 293,
"name": "JUMPDEST"
},
{
"begin": 218,
"end": 293,
"name": "PUSH [tag]",
"value": "8"
},
{
"begin": 218,
"end": 293,
"name": "PUSH [tag]",
"value": "9"
},
{
"begin": 218,
"end": 293,
"name": "JUMP"
},
{
"begin": 218,
"end": 293,
"name": "tag",
"value": "8"
},
{
"begin": 218,
"end": 293,
"name": "JUMPDEST"
},
{
"begin": 218,
"end": 293,
"name": "STOP"
},
{
"begin": 88,
"end": 173,
"name": "tag",
"value": "6"
},
{
"begin": 88,
"end": 173,
"name": "JUMPDEST"
},
{
"begin": 163,
"end": 165,
"name": "PUSH",
"value": "2A"
},
{
"begin": 88,
"end": 173,
"name": "SWAP1"
},
{
"begin": 88,
"end": 173,
"name": "JUMP",
"value": "[out]"
},
{
"begin": 218,
"end": 293,
"name": "tag",
"value": "9"
},
{
"begin": 218,
"end": 293,
"name": "JUMPDEST"
},
{
"begin": 264,
"end": 285,
"name": "PUSH",
"value": "33F40E50FFA7656E1B1AC2BC9082F86C6DBC78583C95DA9A387C7B0E09478387"
},
{
"begin": 281,
"end": 283,
"name": "PUSH",
"value": "2A"
},
{
"begin": 264,
"end": 285,
"name": "PUSH",
"value": "40"
},
{
"begin": 264,
"end": 285,
"name": "MLOAD"
},
{
"begin": 264,
"end": 285,
"name": "PUSH",
"value": "0"
},
{
"begin": 264,
"end": 285,
"name": "SWAP2"
},
{
"begin": 264,
"end": 285,
"name": "SWAP1"
},
{
"begin": 264,
"end": 285,
"name": "SWAP2"
},
{
"begin": 264,
"end": 285,
"name": "SIGNEXTEND"
},
{
"begin": 264,
"end": 285,
"name": "DUP2"
},
{
"begin": 264,
"end": 285,
"name": "MSTORE"
},
{
"begin": 264,
"end": 285,
"name": "PUSH",
"value": "20"
},
{
"begin": 264,
"end": 285,
"name": "ADD"
},
{
"begin": 264,
"end": 285,
"name": "PUSH",
"value": "40"
},
{
"begin": 264,
"end": 285,
"name": "MLOAD"
},
{
"begin": 264,
"end": 285,
"name": "DUP1"
},
{
"begin": 264,
"end": 285,
"name": "SWAP2"
},
{
"begin": 264,
"end": 285,
"name": "SUB"
},
{
"begin": 264,
"end": 285,
"name": "SWAP1"
},
{
"begin": 264,
"end": 285,
"name": "LOG1"
},
{
"begin": 218,
"end": 293,
"name": "JUMP",
"value": "[out]"
}
]
}
}
},
"bytecode": "6060604052341561000f57600080fd5b60f18061001d6000396000f30060606040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166312065fe08114604d57806364444dd4146073575b600080fd5b3415605757600080fd5b605d6085565b60405160ff909116815260200160405180910390f35b3415607d57600080fd5b6083608a565b005b602a90565b7f33f40e50ffa7656e1b1ac2bc9082f86c6dbc78583c95da9a387c7b0e09478387602a60405160009190910b815260200160405180910390a15600a165627a7a723058201dca2871e6fcc1b84c49b2bd9909e37228b077200c81c1af42b11a10d983ff910029",
"functionHashes": {
"getBalance()": "12065fe0",
"getBalanceEvent()": "64444dd4"
},
"gasEstimates": {
"creation": [
94,
48200
],
"external": {
"getBalance()": 182,
"getBalanceEvent()": 1215
},
"internal": {}
},
"interface": "[{"constant":true,"inputs":[],"name":"getBalance","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"getBalanceEvent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"int8"}],"name":"balanceChanged","type":"event"}]",
"metadata": "{"compiler":{"version":"0.4.21+commit.dfe3193c"},"language":"Solidity","output":{"abi":[{"constant":true,"inputs":[],"name":"getBalance","outputs":[{"name":"","type":"uint8"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"getBalanceEvent","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"name":"value","type":"int8"}],"name":"balanceChanged","type":"event"}],"devdoc":{"methods":{}},"userdoc":{"methods":{}}},"settings":{"compilationTarget":{"":"Trivial"},"evmVersion":"byzantium","libraries":{},"optimizer":{"enabled":true,"runs":200},"remappings":[]},"sources":{"":{"keccak256":"0x67ca7c5ea74a6a7efbd01b3eebbe43c263dbbf6ab4a8c16b5ff54ada4afed01f","urls":["bzzr://73f487445177e04a0169d655e93832490450811e8b019b1d3658177e7609c2c6"]}},"version":1}",
"opcodes": "PUSH1 0x60 PUSH1 0x40 MSTORE CALLVALUE ISZERO PUSH2 0xF JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0xF1 DUP1 PUSH2 0x1D PUSH1 0x0 CODECOPY PUSH1 0x0 RETURN STOP PUSH1 0x60 PUSH1 0x40 MSTORE PUSH1 0x4 CALLDATASIZE LT PUSH1 0x48 JUMPI PUSH4 0xFFFFFFFF PUSH29 0x100000000000000000000000000000000000000000000000000000000 PUSH1 0x0 CALLDATALOAD DIV AND PUSH4 0x12065FE0 DUP2 EQ PUSH1 0x4D JUMPI DUP1 PUSH4 0x64444DD4 EQ PUSH1 0x73 JUMPI JUMPDEST PUSH1 0x0 DUP1 REVERT JUMPDEST CALLVALUE ISZERO PUSH1 0x57 JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x5D PUSH1 0x85 JUMP JUMPDEST PUSH1 0x40 MLOAD PUSH1 0xFF SWAP1 SWAP2 AND DUP2 MSTORE PUSH1 0x20 ADD PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 RETURN JUMPDEST CALLVALUE ISZERO PUSH1 0x7D JUMPI PUSH1 0x0 DUP1 REVERT JUMPDEST PUSH1 0x83 PUSH1 0x8A JUMP JUMPDEST STOP JUMPDEST PUSH1 0x2A SWAP1 JUMP JUMPDEST PUSH32 0x33F40E50FFA7656E1B1AC2BC9082F86C6DBC78583C95DA9A387C7B0E09478387 PUSH1 0x2A PUSH1 0x40 MLOAD PUSH1 0x0 SWAP2 SWAP1 SWAP2 SIGNEXTEND DUP2 MSTORE PUSH1 0x20 ADD PUSH1 0x40 MLOAD DUP1 SWAP2 SUB SWAP1 LOG1 JUMP STOP LOG1 PUSH6 0x627A7A723058 KECCAK256 SAR 0xca 0x28 PUSH18 0xE6FCC1B84C49B2BD9909E37228B077200C81 0xc1 0xaf TIMESTAMP 0xb1 BYTE LT 0xd9 DUP4 SELFDESTRUCT SWAP2 STOP 0x29 ",
"runtimeBytecode": "60606040526004361060485763ffffffff7c010000000000000000000000000000000000000000000000000000000060003504166312065fe08114604d57806364444dd4146073575b600080fd5b3415605757600080fd5b605d6085565b60405160ff909116815260200160405180910390f35b3415607d57600080fd5b6083608a565b005b602a90565b7f33f40e50ffa7656e1b1ac2bc9082f86c6dbc78583c95da9a387c7b0e09478387602a60405160009190910b815260200160405180910390a15600a165627a7a723058201dca2871e6fcc1b84c49b2bd9909e37228b077200c81c1af42b11a10d983ff910029",
"srcmap": "26:269:0:-;;;49:33;;;;;;;;26:269;;;;;;",
"srcmapRuntime": "26:269:0:-;;;;;;;;;;;;;;;;;;;;;;;;;;;;88:85;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;218:75;;;;;;;;;;;;;;88:85;163:2;88:85;:::o;218:75::-;264:21;281:2;264:21;;;;;;;;;;;;;;;;;;218:75::o"
}
key files [ 'UTC--2018-04-12T17-08-32.610839630Z--7b7213e2343ee0257dadeb233d453df62cbf2610' ]
file UTC--2018-04-12T17-08-32.610839630Z--7b7213e2343ee0257dadeb233d453df62cbf2610
Wallet: {
"privateKey": "0xc8ad61a16d87b25360b732e592942a45f67d302470f25fae61eb4de04baf2561",
"provider": {
"chainId": 87,
"ensAddress": null,
"_events": {},
"_emitted": {
"block": -1
},
"url": "http://localhost:8545"
},
"defaultGasLimit": 1500000,
"address": "0x7B7213e2343ee0257daDEb233D453DF62CBF2610"
}
after getDeployTransaction { data: '0x060006000600040005020304010506010000000005070600000008000000050006000001080006010000010006000000030906000000000300000600060006000400050206000004030601000600040805070603000000000000000007000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000030500040106060301020006050000000801010406000400050708000603060404040400000401040600070305070500060000000800000005000304010506000507050706000000080000000500060005000600080505060500060004000501060000000900090101060801050206000200000106000400050108000901000309000003050003040105060007000507060000000800000005000600080306000800050605000000050006000200090005060500070003030004000005000000000706050600010001000002000009000802000806000600000007080508030009050000090003080700070000000009040708030807060002000600040005010600000009010900090100000801050206000200000106000400050108000901000309000001050600000001060506020700070007020300050802000100000002080701000600000001000804000409000200000909000900030702020800000707020000000801000100000402000101000100000908030000090100000209' }
after sendTransaction { nonce: 33,
gasPrice: BigNumber { _bn: <BN: 430e23400> },
gasLimit: BigNumber { _bn: <BN: 16e360> },
value: BigNumber { _bn: <BN: 0> },
data: '0x060006000600040005020304010506010000000005070600000008000000050006000001080006010000010006000000030906000000000300000600060006000400050206000004030601000600040805070603000000000000000007000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000030500040106060301020006050000000801010406000400050708000603060404040400000401040600070305070500060000000800000005000304010506000507050706000000080000000500060005000600080505060500060004000501060000000900090101060801050206000200000106000400050108000901000309000003050003040105060007000507060000000800000005000600080306000800050605000000050006000200090005060500070003030004000005000000000706050600010001000002000009000802000806000600000007080508030009050000090003080700070000000009040708030807060002000600040005010600000009010900090100000801050206000200000106000400050108000901000309000001050600000001060506020700070007020300050802000100000002080701000600000001000804000409000200000909000900030702020800000707020000000801000100000402000101000100000908030000090100000209',
v: 210,
r: '0xd01001fe98de6bf1902aaedd819973c86cea9a435e263ff8fc15bc3a6200c055',
s: '0x7278748cdb74741fc42eddb3021cc6ebd6993d992ce433943870f0df791e1b02',
chainId: 87,
from: '0x7B7213e2343ee0257daDEb233D453DF62CBF2610',
hash: '0xf19c4905a57cf652226cf9da2ecc8407e2ba1ee5363a8b756c02a52706f71b5a',
wait: [Function] }
transaction response { hash: '0xf19c4905a57cf652226cf9da2ecc8407e2ba1ee5363a8b756c02a52706f71b5a',
blockHash: '0x94a42cb9dfb5487bf08dfa6ed7ebbe1ba9e77d11c533a14010b1573539bb48ee',
blockNumber: 4133,
transactionIndex: 0,
from: '0x7B7213e2343ee0257daDEb233D453DF62CBF2610',
gasPrice: BigNumber { _bn: <BN: 430e23400> },
gasLimit: BigNumber { _bn: <BN: 16e360> },
to: null,
value: BigNumber { _bn: <BN: 0> },
nonce: 33,
data: '0x060006000600040005020304010506010000000005070600000008000000050006000001080006010000010006000000030906000000000300000600060006000400050206000004030601000600040805070603000000000000000007000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006000000030500040106060301020006050000000801010406000400050708000603060404040400000401040600070305070500060000000800000005000304010506000507050706000000080000000500060005000600080505060500060004000501060000000900090101060801050206000200000106000400050108000901000309000003050003040105060007000507060000000800000005000600080306000800050605000000050006000200090005060500070003030004000005000000000706050600010001000002000009000802000806000600000007080508030009050000090003080700070000000009040708030807060002000600040005010600000009010900090100000801050206000200000106000400050108000901000309000001050600000001060506020700070007020300050802000100000002080701000600000001000804000409000200000909000900030702020800000707020000000801000100000402000101000100000908030000090100000209',
r: '0xd01001fe98de6bf1902aaedd819973c86cea9a435e263ff8fc15bc3a6200c055',
s: '0x7278748cdb74741fc42eddb3021cc6ebd6993d992ce433943870f0df791e1b02',
v: 210,
creates: '0xD2C190842db99212C3d918Ff75370D58d3846698',
raw: '0xf9027021850430e234008316e3608080b9021c06000600060004000502030401050601000000000507060000000800000005000600000108000601000001000600000003090600000000030000060006000600040005020600000403060100060004080507060300000000000000000700000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000003050004010606030102000605000000080101040600040005070800060306040404040000040104060007030507050006000000080000000500030401050600050705070600000008000000050006000500060008050506050006000400050106000000090009010106080105020600020000010600040005010800090100030900000305000304010506000700050706000000080000000500060008030600080005060500000005000600020009000506050007000303000400000500000000070605060001000100000200000900080200080600060000000708050803000905000009000308070007000000000904070803080706000200060004000501060000000901090009010000080105020600020000010600040005010800090100030900000105060000000106050602070007000702030005080200010000000208070100060000000100080400040900020000090900090003070202080000070702000000080100010000040200010100010000090803000009010000020981d2a0d01001fe98de6bf1902aaedd819973c86cea9a435e263ff8fc15bc3a6200c055a07278748cdb74741fc42eddb3021cc6ebd6993d992ce433943870f0df791e1b02',
networkId: 87 }
Error: Error: invalid uint8
at throwError (/home/michael/blockchain/trivial/node_modules/ethers/utils/throw-error.js:4:17)
at Object.decode (/home/michael/blockchain/trivial/node_modules/ethers/utils/abi-coder.js:73:46)
at /home/michael/blockchain/trivial/node_modules/ethers/utils/abi-coder.js:292:32
at Array.forEach (
const fs = require ('fs' ) ; const ethers = require ('ethers' ) ; const solc = require ('solc' ) ; const sleep = require ('sleep' ) ;
function getKeyFile () {
var keyFile ;
const keyFiles = fs.readdirSync ( /home/michael/blockchain/mining/gethdir/keystore ) ;
console.log ( " key files " , keyFiles ) ;
for ( let i = 0 ; i < keyFiles.length ; i ++ ) {
let file = keyFiles [i] ;
console.log ( " file " , file ) ;
let stat = fs.statSync ( /home/michael/blockchain/mining/gethdir/keystore/${file} ) ;
if ( stat.isFile() ) {
if ( file.indexOf ( "UTC" ) >= 0 ) {
keyFile = file ;
break ;
}
}
}
return keyFile ;
}
var bytesToHex = function(bytes) { for (var hex = [], i = 0; i < bytes.length; i++) { /* jshint ignore:start / hex.push((bytes[i] >>> 4).toString(16)); hex.push((bytes[i] & 0xF).toString(16)); / jshint ignore:end */ } return '0x'+ hex.join(""); };
const source = fs.readFileSync ( './contracts/Trivial.sol' , 'utf8' ) ; const compile = solc.compile ( source , 1).contracts [ ':Trivial' ] ; console.log ( " compile " , JSON.stringify ( compile , undefined , 2 ) ) ; const byteCode = bytesToHex ( compile.bytecode ) ;
const network = { chainId: 87 } ;
const provider = new ethers.providers.JsonRpcProvider( http://localhost:8545 , network ) ;
const keyFile = getKeyFile() ;
const keyStore = fs.readFileSync ( /home/michael/blockchain/mining/gethdir/keystore/${keyFile} , "utf8" ) ;
const password = 'Handel' ;
let txData = { gasLimit: 110000 /* Only used in raft mode */ } ;
process.raft = false ;
ethers.Wallet.fromEncryptedWallet( keyStore , password ).then ( async wallet => { // console.log ( " accounts " , await web3.eth.getAccounts() ) ; wallet.provider = provider ; console.log ( "Wallet: " , JSON.stringify ( wallet , undefined , 2 ) ); // Deploy new contract let contract = await ethers.Contract.getDeployTransaction ( byteCode, JSON.parse ( compile.interface ) ) ; console.log ( " after getDeployTransaction " , contract ) ; let request = await wallet.sendTransaction ( contract ) ; console.log ( " after sendTransaction " , request ) ; let response = await request.wait() ; console.log ( " transaction response " , response ) ; // Balance test let example = await new ethers.Contract ( response.creates , JSON.parse ( compile.interface ) , wallet ) ; example.events.onbalancechanged = function( value ) { console.log('Value: ' , value); } ; let balance = await example.getBalance() ; console.log ( " after balance " , balance ) ; } ).catch ( error => console.log ( "Error: " , error ) ) ;
That all looks good. I don't know why it won't work... One more request. :)
Can you run:
var address = '0xD2C190842db99212C3d918Ff75370D58d3846698';
provider.getCode(address).then(function(code) {
console.log('Code', code);
});
To make sure the contract actually got into the blockchain?
provider.getCode( response.creates ) is returning "0x" .... which can't be good. I was assuming that I had successfully deployed because the transaction response contained an address, transaction hash, etc. but apparently that is not always true!
From: Richard Moore [email protected] Sent: Thursday, April 12, 2018 6:55 PM To: ethers-io/ethers.js Cc: michaelerose; Author Subject: Re: [ethers-io/ethers.js] Unable to call constant solidity functions from ethers.js (#161)
That all looks good. I don't know why it won't work... One more request. :)
Can you run:
var address = '0xD2C190842db99212C3d918Ff75370D58d3846698'; provider.getCode(address).then(function(code) { console.log('Code', code); });
To make sure the contract actually got into the blockchain?
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ethers-io/ethers.js/issues/161#issuecomment-380968874, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADAl4Y06EU0RgwU35V0gwCU0yaMLbU-Aks5tn9tggaJpZM4TSZ3F.
You will still have a valid contract address, even if the contract failed to deploy, since it is computed from only the sending address and the transaction nonce. I didn't see any reason why your contract should fail to deploy though.
To find out the status of a transaction, you need:
provider.getTransactionReceipt(hash).then(function(receipt) {
console.log(receipt);
});
That might help figure out the issue.
I'm closing this issue, as I think we have established it was an issue with the contract getting deployed. The other issue is still open. If this is still an issue, please feel free to re-open. :)
Richard -
Yes, it was a deployment issue .... still not sure, but here's what I think is happening:
(1) Looking at solidity compiler output for a variety of valid contacts, I'm noticing "exception" opcodes INVALID and, possibly, REVERT .... this apparently goes unnoticed until it
reaches the EVM since solc provides no warning messages.
(2) The EVM cannot run this bytecode, which explains the deployment problem
(3) Continuing without checking tx-receipt status or calling getCode results in error messages concerning issues that are well downsteam of the actual problem.
(4) Strangely enough, when I use the same bytecode to deploy directly from the Geth console, everything works as it should for both Ethereum and Quorum local blockchains.
(5) Cannot deploy from web application using same methods and data that deploys correctly from Geth console
(6) Also have no trouble deploying to ganache-cli, which emulates the EVM in its own way.
I need to investigate why the same bytecode and method calls succeed when called from the console but fail when called from a node.js application. Maybe the bytecode is modified in some way between the Geth console and the EVM ... In any case, this has nothing to do with ethers.js.
- Michael
From: Richard Moore [email protected] Sent: Saturday, April 14, 2018 4:30 PM To: ethers-io/ethers.js Cc: michaelerose; Author Subject: Re: [ethers-io/ethers.js] Unable to call constant solidity functions from ethers.js (#161)
I'm closing this issue, as I think we have established it was an issue with the contract getting deployed. The other issue is still open. If this is still an issue, please feel free to re-open. :)
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ethers-io/ethers.js/issues/161#issuecomment-381358325, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADAl4ZAAx8LvKaNXbLqIRvzcgGlOaOjMks5tolxvgaJpZM4TSZ3F.
Richard -
This issue is now resolved ..... the problem was that I incorrectly applied utils.bytesToHex to the compiled bytecode when I should have just prepended "0x" .... his caused a stack underflow exception in the Ethereum VM that was preventing deployment.
I'll try your suggestions concerning the transaction-signing issue and get back to you later today.
Thanks again for your help
- Michael
From: Richard Moore [email protected] Sent: Thursday, April 12, 2018 7:26 PM To: ethers-io/ethers.js Cc: michaelerose; Author Subject: Re: [ethers-io/ethers.js] Unable to call constant solidity functions from ethers.js (#161)
You will still have a valid contract address, even if the contract failed to deploy, since it is computed from only the sending address and the transaction nonce. I didn't see any reason why your contract should fail to deploy though.
To find out the status of a transaction, you need:
provider.getTransactionReceipt(hash).then(function(receipt) { console.log(receipt); });
That might help figure out the issue.
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/ethers-io/ethers.js/issues/161#issuecomment-380974096, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ADAl4ZarsxqmQNakwgkXmzqQ8lGVMqHzks5tn-KUgaJpZM4TSZ3F.