@Lane11 (was not able to ping you, thus) see previous remark
Hi @alp257
I tried, here is the result:
truffle(ganache)> insta.getKitty(1)
Uncaught Error: VM Exception while processing transaction: invalid opcode
at evalmachine.<anonymous>
at sigintHandlersWrap (node:vm:270:12)
at Script.runInContext (node:vm:139:14)
at runScript (C:\Users\lane\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:505:1)
at Console.interpret (C:\Users\lane\AppData\Roaming\npm\node_modules\truffle\build\webpack:\packages\core\lib\console.js:520:1)
at bound (node:domain:433:15)
at REPLServer.runBound [as eval] (node:domain:444:12)
at REPLServer.onLine (node:repl:902:10)
at REPLServer.emit (node:events:513:28)
at REPLServer.emit (node:domain:489:12)
at REPLServer.[_onLine] [as _onLine] (node:internal/readline/interface:422:12)
at REPLServer.[_line] [as _line] (node:internal/readline/interface:893:18)
at REPLServer.[_ttyWrite] [as _ttyWrite] (node:internal/readline/interface:1271:22)
at REPLServer.self._ttyWrite (node:repl:997:9)
at ReadStream.onkeypress (node:internal/readline/interface:270:20)
at ReadStream.emit (node:events:513:28)
at ReadStream.emit (node:domain:489:12)
at emitKeys (node:internal/readline/utils:357:14)
at emitKeys.next (<anonymous>)
at ReadStream.onData (node:internal/readline/emitKeypressEvents:64:36) {
code: -32000,
data: {
hash: null,
programCounter: 1891,
result: '0x',
reason: null,
message: 'invalid opcode'
},
reason: undefined,
hijackedStack: 'Error: VM Exception while processing transaction: invalid opcode\n' +
' at C:\\Users\\lane\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:25:1\n' +
' at C:\\Users\\lane\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\packages\\provider\\wrapper.js:166:1\n' +
' at C:\\Users\\lane\\AppData\\Roaming\\npm\\node_modules\\truffle\\build\\webpack:\\node_modules\\web3-providers-http\\lib\\index.js:127:1\n' +
' at processTicksAndRejections (node:internal/process/task_queues:95:5)'
}
And this is for totalSupply:
inst.totalSupply()
BN { negative: 0, words: [ 0, <1 empty item> ], length: 1, red: null }
length is 1.
Not sure what exactly is happening given the current info, however I do suggest to do try some things that could help understand the problem:
- Create more Kitties
- Check total supply every after creating more Kitties
- Try using the index create Kitty to get the data
Hope these help narrow down the problem
As per the return value of totalSupply, there are no items in kitties array. That explains why insta.getKitty(1) returned error.
As per your previous message you were able to call createKittyGen0 function without any error, so the contract code is working as expected.
So I think if you test the getKitty function after calling createKittyGen0 it should work as expected.
@JohnVersus
I created 3 cats with insta.createKittyGen0(1110)
and when I try to see totalSupply()
this is the output: BN { negative: 0, words: [ 3, <1 empty item> ], length: 1, red: null }
but when I try to call insta.getKitty(0), insta.getKitty(1) or insta.getKitty(2)
, after the creation of 3 cats, I got this:
truffle(ganache)> insta.getKitty(0)
{
tx: '0xa4376cf6e784b700bd492e34e730201d5fe7bdfa26b2875c6bb8a71c278474a2',
receipt: {
transactionHash: '0xa4376cf6e784b700bd492e34e730201d5fe7bdfa26b2875c6bb8a71c278474a2',
transactionIndex: 0,
blockNumber: 8,
blockHash: '0x6a6408972a7c11a53f54671e5e5d3c1edd15b28ed78dad63ebc41f7bd6e5346d',
from: '0xf41bfb88a006c6047550f9c976f628ea49d795bd',
to: '0x071ee359e97af35f43524d57b610f647cfb5b9fe',
cumulativeGasUsed: 28790,
gasUsed: 28790,
contractAddress: null,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
effectiveGasPrice: 2863857297,
type: '0x2',
rawLogs: []
},
logs: []
}
truffle(ganache)> insta.getKitty(1)
{
tx: '0x688f0d1fcf886f957160b650e985d45cc8dbcb382867db5f11c5a4152eccbcba',
receipt: {
transactionHash: '0x688f0d1fcf886f957160b650e985d45cc8dbcb382867db5f11c5a4152eccbcba',
transactionIndex: 0,
blockNumber: 9,
blockHash: '0xd20adebd931d655e8ec8efac70ed96d758ec13dc25036d458328479bfa3a9f10',
from: '0xf41bfb88a006c6047550f9c976f628ea49d795bd',
to: '0x071ee359e97af35f43524d57b610f647cfb5b9fe',
cumulativeGasUsed: 28802,
gasUsed: 28802,
contractAddress: null,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
effectiveGasPrice: 2818764733,
type: '0x2',
rawLogs: []
},
logs: []
}
truffle(ganache)> insta.getKitty(2)
{
tx: '0x31049b402f1d6fbce034bfc4330e38ab646167192f27af8b5313f02fbe7c269a',
receipt: {
transactionHash: '0x31049b402f1d6fbce034bfc4330e38ab646167192f27af8b5313f02fbe7c269a',
transactionIndex: 0,
blockNumber: 10,
blockHash: '0xfe9f3323ca9c65e5259a292feed7a235ee29b654a6536ef0fd5c976442887a97',
from: '0xf41bfb88a006c6047550f9c976f628ea49d795bd',
to: '0x071ee359e97af35f43524d57b610f647cfb5b9fe',
cumulativeGasUsed: 28802,
gasUsed: 28802,
contractAddress: null,
logs: [],
logsBloom: '0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000',
status: true,
effectiveGasPrice: 2779260599,
type: '0x2',
rawLogs: []
},
logs: []
}
That looks good. It is working as expected