I'm trying to deploy basic erc20 example contract on rococo canvas but "contracts.ContractTrapped" error popped on deployment? any hint will be much appreciated, Thanks!
Asked
Active
Viewed 120 times
0
-
Hey, would you be so kind as to repost this great question (with more details) on https://substrate.stackexchange.com/ -- and @Alejandro Martínez over there? Very happy to assist on our shiny new Substrate (and friends) home for your questions! – Nuke Feb 09 '22 at 15:54
2 Answers
1
A common source of
ContractTrapped
are Integer overflows, those can cause your contract to trap as well.
Please, check the source of this paragraph to see if it solves your issue.

Alejandro Martínez
- 451
- 2
- 7
-
Note Solidity checks for overflows since version 0.8 and SafeMath is not required. – Bouke May 24 '22 at 16:50
0
I have had the issue ContractTrapped
while I wanted to add values in Solidity code without SafeMath library. The solution was to ensure safety of a source code like:
function sum(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}

Tomasz Waszczyk
- 2,680
- 5
- 35
- 73
-
Wouldn't it make more sense to declare `require(b >= 0)` as first line within this method? – Bouke May 24 '22 at 16:44
-
-
Because it's easier to understand. Does it not solve the `ContractTrapped` issue anymore then? – Bouke May 24 '22 at 17:49
-
1https://github.com/ConsenSysMesh/openzeppelin-solidity/blob/master/contracts/math/SafeMath.sol#L43 – Tomasz Waszczyk May 24 '22 at 18:30
-
Ah, I see, my comment about making more sense doesn't make sense at all. – Bouke May 24 '22 at 18:57
-
..but curiosity is good, trying to improve things is also good, thanks for the comment, have a good day! ;-) – Tomasz Waszczyk May 24 '22 at 19:04