[英]Solidity Remix transaction reverted to initial state
I am kinda new to solidity and I have this error that keeps popping up after I deployed the contract and run the initTest() function.我对 Solidity 有点陌生,在部署合约并运行 initTest() 函数后,这个错误不断弹出。 What I am trying to do is passing the string that I insert in the initTest() on the runTest so it runs and save the entire string on the blockchain.
我想要做的是传递我在 runTest 的 initTest() 中插入的字符串,以便它运行并将整个字符串保存在区块链上。 I don't have any error when I compile the contrct, only after I deployed it.
我编译contrct时没有任何错误,只有在我部署它之后。
pragma solidity ^0.8.0;
import "../contracts/Code.sol";
contract CodeTest {
ContrIdCard private _UniCode;
bytes[] private CustID;
bytes[] private ContractID ;
function pubblishCode (bytes memory _CustID, bytes memory _ContractID, bool _MultiCustID) private {
_UniCode.mkCode(_CustID, _ContractID, _MultiCustID);
}
function initTest() public {
uint i = 0;
CustID[i] = "04wT9Os3uv7p"; ContractID[i++] = "e7tk6peihfcc6ece1ffbe8f8cd433ae61c1081ae6b94";
}
function runTest(bool _MultiCustID) public {
for (uint i = 0; i<CustID.length; i++)
pubblishCode (CustID[i], ContractID[i], _MultiCustID);
}
function runTest() public {
runTest(false);
}
}
The error given when I run initTest() is: "transact to CodeTest.initTest errored: VM error: revert.运行 initTest() 时给出的错误是:“交易到 CodeTest.initTest 出错:VM 错误:恢复。
revert The transaction has been reverted to the initial state. revert 事务已恢复到初始状态。 Note: The called function should be payable if you send value and the value you send should be less than your current balance.
注意:如果您发送价值并且您发送的价值应小于您当前的余额,则应支付被调用的函数。 Debug the transaction to get more information."
调试事务以获取更多信息。”
When I do the debug it gives me value 0 for the CustID e ContractID.当我进行调试时,它为 CustID e ContractID 提供了值 0。 What can I do to fix it?
我能做些什么来修复它?
I asume that the error is comming from that when you are calling the function runTest()
you are sending ether to it.我假设错误来自当您调用函数
runTest()
您正在向它发送以太。
In order to send ether to a function you should add the payable
modifier to it's definition in the contract.为了将以太发送到函数,您应该在合同中为其定义添加
payable
修饰符。
It should look like this:它应该是这样的:
function runTest(bool _MultiCustID) public payable {
for (uint i = 0; i<CustID.length; i++)
pubblishCode (CustID[i], ContractID[i], _MultiCustID);
}
If you are intrested in learning more about payable functions in solidity you can check the docs如果您有兴趣了解更多关于 Solidity 的应付功能,您可以查看文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.