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.
JavaScript
x
25
25
1
from web3 import HTTPProvider, Web3, exceptions
2
3
w3 = Web3(HTTPProvider('https://ropsten.infura.io/RPw9nHRS7Ue47RaKVvHM'))
4
contract_address = '0x635209612bf0e830ac348ef30357ee4f0e5bf560'
5
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"}]
6
7
instance = w3.eth.contract(
8
address=Web3.toChecksumAddress(contract_address),
9
abi = provider_abi
10
)
11
user_address = "0x25BEADE120E501D7b984498D196eFe4AbE6a11F6"
12
country_key = "country"
13
country_byte_32 = Web3.toHex(Web3.toBytes(text=country_key))
14
print(country_byte_32) # Prints 0x636f756e747279
15
country_val = "IN"
16
country_val_byte_32 = Web3.toHex(Web3.toBytes(text=country_val))
17
print(country_val_byte_32) # Prints 0x494e
18
try:
19
result = instance.call().setProperty(user_address,country_byte_32,country_val_byte_32)
20
print(result) # Prints False
21
except exceptions.MismatchedABI as ve :
22
print(ve)
23
import traceback
24
print(traceback.format_exc())
25
Can someone tell me, how do I provide the access right address?
Advertisement
Answer
To put the value in the form field you can do it like this
JavaScript
1
2
1
result = instance.call({"from": user_address }).setProperty(user_address,country_byte_32,country_val_byte_32)
2