SLContract¶
-
class
SLContract
¶
Abstract¶
This is a helper and wrapper around the w3 contract class.
Constructor¶
-
SLContract
(node, address=None, provided_abi=None)
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)
Properties¶
-
SLContract.
w3
¶
The w3 object as provided by the web3.py library
-
SLContract.
node
¶
The Node
object
-
SLContract.
functions
¶
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)
-
SLContract.
address
¶
The string address of the SLContract.
Methods¶
-
SLContract.
sha3
(data)¶
The sha3 function as used in ethereum contracts.
-
SLContract.
bytes32
(an_int)¶
Turns an int into bytes32 value for use in an ethereum contract.
-
SLContract.
to_sol_addr
(address)¶
Removes the ‘0x’ and hex decodes an address for use in an ethereum contract.
-
SLContract.
toWei
(amount, from_denomination)¶
Equivalent of amount * 10 ** 18
-
SLContract.
fromWei
(amount, to_denomination)¶
Equivalent of amount / 10 ** 18