admin管理员组文章数量:1327803
I am developing ethereum and nextjs project. When project first initlaized I am getting this error:
Error: data out-of-bounds (length=3, offset=32, code=BUFFER_OVERRUN, version=abi/5.0.7)
at Logger.makeError (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/logger/lib/index.js:199:21)
at Logger.throwError (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/logger/lib/index.js:208:20)
at Reader._peekBytes (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:149:24)
at Reader.readBytes (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:161:26)
at Reader.readValue (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:167:48)
at NumberCoder.decode (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/number.js:49:28)
at /home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/array.js:106:31
at Array.forEach (<anonymous>)
at Object.unpack (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/array.js:85:12)
at TupleCoder.decode (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
at AbiCoder.decode (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22)
at ABICoder.decodeParametersWith (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-abi/lib/index.js:303:30)
at ABICoder.decodeParameters (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-abi/lib/index.js:284:17)
at Contract._decodeMethodReturn (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-contract/lib/index.js:469:22)
at Method.outputFormatter (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-contract/lib/index.js:759:42)
at Method.formatOutput (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-core-method/lib/index.js:146:54) {
reason: 'data out-of-bounds',
code: 'BUFFER_OVERRUN',
length: 3,
offset: 32
}
I was getting inside getServerSideProps. Initially I had this
let campaigns;
try {
// in solidity contract, this returns an array of contracts
campaigns = await factory.methods.getDeployedCampaign().call();
} catch (e) {
console.log("error in index server", e);
}
I checked the code, could not find any issue. I thought maybe the issue would be returning an array of addresses. (As far as I know, we cannot return an array of structs from solidity, but array of addresses would be fine). Nevertheless, I decided to get each campaign one by one. So I changed the contract code:
contract CampaignFactory{
address[] public deployedCampaigns;
uint public campaignsCount;
function createCampaign(uint minimum)public{
Campaign newCampaign=new Campaign(minimum,msg.sender);
deployedCampaigns.push(address(newCampaign));
campaignsCount++;
}
// return individual campaign
function getDeployedCampaign(uint index) public view returns(address ){
return deployedCampaigns[index];
}
function getCampaignCounts() public view returns(uint){
return campaignsCount;
}
}
Then I modified the server side code properly:
export async function getServerSideProps(context) {
let campaigns;
let campaignsCount;
try {
// get the number of campaigns
campaignsCount = await factory.methods.getCampaignCounts().call();
campaigns = await Promise.all(
Array(parseInt(campaignsCount))
.fill()
.map((element, index) => {
return factory.methods.getDeployedCampaign(index).call();
})
);
console.log("camapigns in index", campaigns);
} catch (e) {
console.log("error in index server", e);
}
return {
props: { campaigns: campaigns || [] },
};
}
After modification, I still get the same error. But if I refresh the page, I don't see any more errors and I get the data on UI. That makes me think that there is no issue with the contract. it must be something with interaction with javascript.
I am developing ethereum and nextjs project. When project first initlaized I am getting this error:
Error: data out-of-bounds (length=3, offset=32, code=BUFFER_OVERRUN, version=abi/5.0.7)
at Logger.makeError (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/logger/lib/index.js:199:21)
at Logger.throwError (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/logger/lib/index.js:208:20)
at Reader._peekBytes (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:149:24)
at Reader.readBytes (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:161:26)
at Reader.readValue (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/abstract-coder.js:167:48)
at NumberCoder.decode (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/number.js:49:28)
at /home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/array.js:106:31
at Array.forEach (<anonymous>)
at Object.unpack (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/array.js:85:12)
at TupleCoder.decode (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/coders/tuple.js:39:49)
at AbiCoder.decode (/home/Documents/projects/ethereum/kickstarter/node_modules/@ethersproject/abi/lib/abi-coder.js:93:22)
at ABICoder.decodeParametersWith (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-abi/lib/index.js:303:30)
at ABICoder.decodeParameters (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-abi/lib/index.js:284:17)
at Contract._decodeMethodReturn (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-contract/lib/index.js:469:22)
at Method.outputFormatter (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-eth-contract/lib/index.js:759:42)
at Method.formatOutput (/home/Documents/projects/ethereum/kickstarter/node_modules/web3-core-method/lib/index.js:146:54) {
reason: 'data out-of-bounds',
code: 'BUFFER_OVERRUN',
length: 3,
offset: 32
}
I was getting inside getServerSideProps. Initially I had this
let campaigns;
try {
// in solidity contract, this returns an array of contracts
campaigns = await factory.methods.getDeployedCampaign().call();
} catch (e) {
console.log("error in index server", e);
}
I checked the code, could not find any issue. I thought maybe the issue would be returning an array of addresses. (As far as I know, we cannot return an array of structs from solidity, but array of addresses would be fine). Nevertheless, I decided to get each campaign one by one. So I changed the contract code:
contract CampaignFactory{
address[] public deployedCampaigns;
uint public campaignsCount;
function createCampaign(uint minimum)public{
Campaign newCampaign=new Campaign(minimum,msg.sender);
deployedCampaigns.push(address(newCampaign));
campaignsCount++;
}
// return individual campaign
function getDeployedCampaign(uint index) public view returns(address ){
return deployedCampaigns[index];
}
function getCampaignCounts() public view returns(uint){
return campaignsCount;
}
}
Then I modified the server side code properly:
export async function getServerSideProps(context) {
let campaigns;
let campaignsCount;
try {
// get the number of campaigns
campaignsCount = await factory.methods.getCampaignCounts().call();
campaigns = await Promise.all(
Array(parseInt(campaignsCount))
.fill()
.map((element, index) => {
return factory.methods.getDeployedCampaign(index).call();
})
);
console.log("camapigns in index", campaigns);
} catch (e) {
console.log("error in index server", e);
}
return {
props: { campaigns: campaigns || [] },
};
}
After modification, I still get the same error. But if I refresh the page, I don't see any more errors and I get the data on UI. That makes me think that there is no issue with the contract. it must be something with interaction with javascript.
Share Improve this question edited Oct 5, 2021 at 13:16 Yilmaz asked Oct 5, 2021 at 2:27 YilmazYilmaz 49.8k18 gold badges216 silver badges270 bronze badges2 Answers
Reset to default 3I had this same problem while working with Polygon. I had to change my rpc url from the wss to the https one. Don't know if this helps but thought I'd suggest.
Tip: Check your ABI.
In my case, my function returns a tuple with 1 uint256 and 3 strings, but in my ABI it was returning 4 strings in this tuple.
Example:
struct Contact{
uint256 id;
string symbol;
string address_;
string nickname;
}
function getContacts(address from, string calldata symbol, uint256 fromId, uint256 length) external view returns (Contact[] memory) {
...
}
In the ABI, it was:
{"inputs": [{"internalType": "address","name": "from","type": "address"},
{"internalType": "string","name": "symbol","type": "string"},
{"internalType": "uint256","name": "fromId","type": "uint256"},
{"internalType": "uint256","name": "length","type": "uint256"}],
"name": "getContacts",
"outputs": [{"ponents": [{"internalType": "uint256","name": "id","type": "uint256"},
{"internalType": "string","name": "symbol","type": "string"},
{"internalType": "string","name": "address_","type": "string"},
{"internalType": "string","name": "nickname","type": "string"},
{"internalType": "string","name": "OTHERTHING","type": "string"}],//<-- ERROR
"internalType": "struct Contacts.Contact[]","name": "","type": "tuple[]"}],
"stateMutability": "view", "type": "function"},
Check your ABI and remove some invalid values.
本文标签:
版权声明:本文标题:javascript - Error: data out-of-bounds (length=3, offset=32, code=BUFFER_OVERRUN, version=abi5.0.7) next-js, ethereum - Stack Ov 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742234961a2437909.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论