如何从 react.js 向 Solidity 智能合约发送多个函数参数?

问题描述

我正在尝试调用一个接受多个参数(8 个参数)的 solidity 合约函数。 这是我的合约函数

function generatePet(
                           uint256 _petPrice,string memory contentHash,string memory _name,string memory _akcPopularity,string memory _height,string memory _weight,string memory _lifeExpectancy,string memory _group
                           ) public returns(bool) {
         
         require(msg.sender != address(0),"Please! Check back! Registeration should not be from zero address");
         require(msg.sender == owner,"Only contract owner can generate more pets");
         
         tokenId++;
         require(tokenId <= 16,"More than 16 pets is not allowed");
         
         priceMapping[tokenId] = _petPrice;
         tokenIdToOffchainContentHash[tokenId] = contentHash;
         _mint(owner,tokenId);
         emit PetGenerated(owner,tokenId,_petPrice,contentHash,_name,_akcPopularity,_height,_weight,_lifeExpectancy,_group);
         return true;
       }

我现在正在尝试使用 @drizzle/react-plugin: "^1.5.3" @drizzle/store": "^1.5.3" 并做出反应。我正在尝试从反应 UI 调用函数调用generatePet函数代码是这样的,


const initialValues = {
    petPrice: '',contentHash: '',petName: '',akcPopularity: '',height: '',weight: '',lifeExpectancy: '',group: ''
  }


const [values,setValues] = useState(initialValues);
const drizzleData = useContext(DrizzleContext.Context);

const sendData = (petPrice,petName,akcPopularity,height,weight,lifeExpectancy,group) => {
      const { drizzle,drizzleState } = drizzleData;
      const contract = drizzle.contracts.PetShop;
  
      // let drizzle kNow we want to call the `set` method with `value`
      const stackId = contract.methods["generatePet"].cacheSend(petPrice,group,{
        from: drizzleState.accounts[0]
      });
  
      console.log('value',petPrice,group)
      console.log('stackId',stackId)
      console.log('drzzleState',drizzleState)
    };

const handleInputChange = (e) => {
      const { name,value } = e.target;

      setValues({
        ...values,[name]: value,});
    };
<form onSubmit={sendData}>
        <br />
        <label htmlFor='petPrice' >Pet Price </label><br/>
        <input type='text' value={values.petPrice} onChange={handleInputChange} name='petPrice'  id='petPrice' maxLength="50" /><br/>
        <label htmlFor='ipfsHash' >IPFS Content Hash </label><br/>
        <input type='text' value={values.contentHash} onChange={handleInputChange} name='contentHash'  id='contentHash' maxLength="50" /><br/>
        <label htmlFor='petName' >Pet Name </label><br/>
        <input type='text' value={values.petName} onChange={handleInputChange} name='petName'  id='petName' maxLength="50" /><br/>
        <label htmlFor='akcPopularity' >AKC Popularity </label><br/>
        <input type='text' value={values.akcPopularity} onChange={handleInputChange} name='akcPopularity'  id='akcPopularity' maxLength="50" /><br/>
        <label htmlFor='height' >Pet Height </label><br/>
        <input type='text' value={values.height} onChange={handleInputChange} name='height'  id='height' maxLength="50" /><br/>
        <label htmlFor='weight' >Pet Weight </label><br/>
        <input type='text' value={values.weight} onChange={handleInputChange} name='weight'  id='weight' maxLength="50" /><br/>
        <label htmlFor='lifeExpectancy' >Life Expectancy </label><br/>
        <input type='text' value={values.lifeExpectancy} onChange={handleInputChange} name='lifeExpectancy'  id='lifeExpectancy' maxLength="50" /><br/>
        <label htmlFor='group' >Group </label><br/>
        <input type='text' value={values.group} onChange={handleInputChange} name='group'  id='group' maxLength="50" /><br/>
        <input type="submit" value="Set Data" onSubmit={formHandleSubmit}/>
     </form>

问题

当我尝试调用函数时,没有任何反应没有打开元掩码,我正在使用 ganache,我错过了什么?提交有什么问题吗?

请帮帮我

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...