1

I have a smart contract address for security tokens, and certain functions of it are protected by access rights, for which I have an address to access those functions, however I am not able to figure out, how to call that function by specifying the rights.

from web3 import HTTPProvider, Web3, exceptions

w3 = Web3(HTTPProvider('https://ropsten.infura.io/RPw9nHRS7Ue47RaKVvHM'))
contract_address = '0x635209612bf0e830ac348ef30357ee4f0e5bf560'
provider_abi =  [{"anonymous":False,"inputs":[{"indexed":False,"name":"addr","type":"address"},{"indexed":False,"name":"propertyKey","type":"bytes32"},{"indexed":False,"name":"propertyValue","type":"bytes32"}],"name":"PropertySet","type":"event"},{"constant":False,"inputs":[{"name":"_addr","type":"address"},{"name":"_propertyKey","type":"bytes32"},{"name":"_propertyValue","type":"bytes32"}],"name":"setProperty","outputs":[{"name":"","type":"bool"}],"payable":False,"stateMutability":"nonpayable","type":"function"},{"constant":True,"inputs":[{"name":"_addr","type":"address"},{"name":"_propertyKey","type":"bytes32"}],"name":"getProperty","outputs":[{"name":"","type":"bytes32"}],"payable":False,"stateMutability":"view","type":"function"}]

instance = w3.eth.contract(
    address=Web3.toChecksumAddress(contract_address),
    abi = provider_abi
)
user_address = "0x25BEADE120E501D7b984498D196eFe4AbE6a11F6"
country_key = "country"
country_byte_32 = Web3.toHex(Web3.toBytes(text=country_key))
print(country_byte_32) # Prints 0x636f756e747279
country_val = "IN"
country_val_byte_32 = Web3.toHex(Web3.toBytes(text=country_val))
print(country_val_byte_32) # Prints 0x494e
try:
    result = instance.call().setProperty(user_address,country_byte_32,country_val_byte_32)
    print(result) # Prints False
except exceptions.MismatchedABI as ve :
    print(ve)
    import traceback
    print(traceback.format_exc())

Can someone tell me, how do I provide the access right address?

2

If you want to call a function of your contract by sending a new transaction, you have to use myFunction.transact(transactionObject). The transactionObject is a dictionnary where you can specify the values for value, gas, from, etc...

Using web3py 4.9.1, it should be the following for your case : instance.functions.setProperty(user_address,country_byte_32,country_val_byte_32).transact({"from":ACCOUNT CONTROLLED BY WEB3})

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.