This is a helper and wrapper around the w3 contract class.
Initialize an SLContract by passing it the Node
object.
The SLContract must be fed an address and the abi, but you have options for how to do this:
You can pass the string keyword arg address
to the constuctor, or optionally you can subclass SLContract and assign the address to constants such as MAINNET
, ROPSTEN
, KOVAN
, and other etherum network names.
You can pass the the string keyword arg provided_abi
to the constructor, or optionally you can subclass SLContract and assign the JSON abi string to the ABI
constant.
abi = '''[{"constant":false,"inputs":[{"name":"owner_", "type":"address"}]
,"name":"setOwner","outputs":[], "payable":false,"stateMutability":"nonpayable",
"type":"function"}'''
contract_address='0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359'
''' then, get the node and...'''
contract = SLContract(node, address=contract_address, provided_abi=abi)
from shadowlands.sl_contract import SLContract
class SaiPip(SLContract):
KOVAN='0xa944bd4b25c9f186a846fd5668941aa3d3b8425f'
ABI='[{"constant":false,"inputs":[{"name":"owner_","type":"address"}],
"name":"setOwner","outputs":[],"payable":false,
"stateMutability":"nonpayable","type":"function"}'
''' then, later, import SaiPip, get the node and...'''
sai_pip = SaiPip(node)
The w3 object as provided by the web3.py library
The Node
object
This is an autogenerated object that contains the contract function generators as described in the ABI the SLContract was initialized with.
Passed through from the web3.py Contract object.
abi = '''[{"constant":false,"inputs":[{"name":"owner_", "type":"address"}]
,"name":"setOwner","outputs":[], "payable":false,"stateMutability":"nonpayable",
"type":"function"}'''
contract_address='0x89d24A6b4CcB1B6fAA2625fE562bDD9a23260359'
''' then, get the node and...'''
contract = SLContract(node, address=contract_address, provided_abi=abi)
set_owner_fn = contract.functions.setOwner(node.credstick.address)
The string address of the SLContract.
The sha3 function as used in ethereum contracts.
Turns an int into bytes32 value for use in an ethereum contract.
Removes the '0x' and hex decodes an address for use in an ethereum contract.
Equivalent of amount * 10 ** 18
Equivalent of amount / 10 ** 18