hello dear community I wanted to ask why the transaction is not executed correctly.
Code Solidity:
// SPDX-License-Identifier: agpl-3.0
pragma solidity 0.8.9;
contract main{
struct data{
string data;
uint num1;
uint num2;
uint num3;
}
mapping(string => data[]) public Data;
address internal owner;
function getOwner() public view returns(address){
return owner;
}
modifier onlyOwner(){
require(getOwner()==msg.sender, "solo el creado puede modificar.");
_;
}
function arrayStructData( data[] memory _data) public{
for(uint i=0; i<_data.length; i++){
Data[_data[i].data].push(data(_data[i].data,_data[i].num1,_data[i].num2,_data[i].num3));
}
}
}
Code Python:
publicKey="0x..."
privateKey= "0x..."
addresscontract= "0x..."
abi="[[...]...]"
contrato= web3.eth.contract(address=addresscontract,abi=abi)
data=[["data",123,321,456],["data2",123,321,456]]
nonce = web3.eth.getTransactionCount(publicKey)
tx= contrato.functions.arrayStructData(data).buildTransaction({
"from":publicKey,
"chainId": web3.eth.chain_id,
"gas": 70000,
"gasPrice": web3.toWei("40", "gwei"),
"nonce": nonce,
})
signed_txn =web3.eth.account.signTransaction(tx, private_key=privateKey)
tx_hash=web3.eth.sendRawTransaction(signed_txn.rawTransaction)
txid = tx_hash.hex()
print({"Tx Hash":txid})
I have tried the combinations with this variable 'data' in Python:
Num= Decimal(3321)
data= (("node1",Num,Num,Num),("node1",Num,Num,Num))
data= (["node1",3123,3321,3456],["node1",3123,3321,3456])
data= (["node1",Num,Num,Num],["node1",Num,Num,Num])
data= ["node1",Num,Num,Num,"node1",Num,Num,Num]
data= (["node1",str(Num),str(Num),str(Num)],["node1",str(Num),str(Num),str(Num)])
data= (["node1",str(3123),str(3321),str(3456)],["node1",str(3123),str(3321),str(3456)])
With these two combinations it is confirmed in the blockchain but fail and not append data.
data= [["node1",3123,3321,3456],["node1",3123,3321,3456]]
data= [("node1",3123,3321,3456),("node1",3123,3321,3456)]
Now my question is what am I doing wrong?
How do I organize it so that the transaction is confirmed and it is successful to add to the contract?
How do you pass a struct in Python by parameter so that it processes it correctly in the contract??
Thank you very much for your answers in advance.