简体   繁体   English

Solidity Remix 交易恢复到初始状态

[英]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.

相关问题 当我测试我的可靠性代码时,我收到“AssertionError: Expected transaction to be reverted with Username” - I am getting "AssertionError: Expected transaction to be reverted with Username " when I am testing my solidity code 如何解决solidity Remix中的类型错误 - how to solve type error in solidity Remix 带有未签名交易 object 的 Solidity 交易 - Solidity transaction with an unsigned transaction object Solidity 交易问题 - Solidity Transaction Issue remix solidity contract如何将多个参数传递给create按钮 - remix solidity contract how to pass multiple arguments into the create button Remix solidity 不会在私有以太坊链上返回结果 - Remix solidity does not return result on private ethereum chain Solidity function 在混音中返回真,但在 web3 function 调用中返回假 - Solidity function returning true in remix but false in web3 function call 在 web3.py 中检测恢复的事务 - Detect reverted transaction in web3.py 如何在合约中设置 ETH 的接收者,以在 remix IDE 中使用solidity usign call() 从一个地址向另一个地址发送ETH - How to set the receiver of ETH in a contract to send ETH from one address to another with solidity usign call() in remix IDE 已解决 | Solidity:在 Remix IDE 上正确返回布尔值,但在 JS 上总是返回“false” - SOLVED | Solidity: the bool values returned correctly on Remix IDE but always return "false" on JS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM