I want to call this method updateRewardsPercentageByTokens() , with web3.py but I fail . please can you help me find a solution
updateRewardsPercentageByTokens code :
function updateRewardsPercentageByTokens(EchelonReward[] memory newEchlonArray) public onlyOwner {
if (0 != newEchlonArray.length) {
delete rewardsPercentageByTokens;
for (uint index = 0; index < newEchlonArray.length; index++) {
EchelonReward memory echelon;
echelon.echelonMaxValue = newEchlonArray[index].echelonMaxValue * 10 ** uint256(decimals());
echelon.percentage = newEchlonArray[index].percentage;
rewardsPercentageByTokens[index] = echelon;
}
}
}
struct code :
struct EchelonReward {
uint256 echelonMaxValue;
uint256 percentage;
}
my code to call the function
from flask_restful import Resource,reqparse
from data import *
import argparse
class updateRewardsPercentageByTokens(Resource):
parser = argparse.ArgumentParser()
parser.add_argument('-a', nargs="+", type=int)
parser.add_argument('-b', nargs="+", type=int)
parser.add_argument('-fromA',help="please put the from address")
parser.add_argument('-gas',type=int,help="please put the amount of gas")
def get (self):
nonce = web3.eth.getTransactionCount(account)
data = updateRewardsPercentageByTokens.parser.parse_args([])
fromAddress = data.fromA
gas = data.gas
a = data.a
b = data.b
c = dict(echelonMaxValue="100000",percentage="2")
#{'newEchlonArray': ['1', '10000']}
#{'echelonMaxValue': ['10000'], 'percentage': [1]}
#{"echelonMaxValue": 1000, "percentage": 1}
print(c)
try :
print('here')
print(a)
print(b)
print(gas)
print(fromAddress)
tx = contract.functions.updateRewardsPercentageByTokens({'newEchlonArray':[500000000000000000000,1]}).transact({
'chainId': 3,
'from': fromAddress,
'gas' : gas,
'gasPrice' : web3.toWei('100', 'gwei'),
'nonce': nonce,
})
#sign the transaction
signed_tx = web3.eth.account.sign_transaction(tx,wallet_private_key)
#get the transaction hash
tx_hash = web3.eth.send_raw_transaction(signed_tx.rawTransaction)
print(web3.toHex(tx_hash))
#waiting for the trasaction receipt
receipt = web3.eth.wait_for_transaction_receipt(tx_hash,timeout=3600, poll_latency=0.1)
#convert the result from dict to json
tx_dict = dict(receipt)
tx_json = Web3.toJSON(tx_dict)
#return result sous format json
return json.loads(tx_json),201
except Exception as e :
print (str(e))
return {'error': str(e)},401