我有一个用于安全令牌的智能合约地址,它的某些功能受访问权限的保护,我有一个地址可以访问这些功能,但是我不知道如何通过以下方式调用该功能指定权利。
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())
有人可以告诉我,我如何提供访问权限地址?
答案 0 :(得分:0)
要将值放在表单字段中,您可以这样操作
result = instance.call({"from": user_address }).setProperty(user_address,country_byte_32,country_val_byte_32)