neo3.api.wrappers
Convenience wrappers for calling smart contracts via RPC.
The most specific wrappers in this module are for NEOs native contracts NeoToken
, GasToken
, PolicyContract
and
RoleManagement
. The ContractManagement
and Ledger
contracts are not wrapped. See the FAQ for the reasons.
One step up are wrappers for contracts following the NEP-17 Token standard (NEP17Contract
) and NEP-11 NFT standard
(NEP11DivisibleContract
& NEP11NonDivisibleContract
).
As last resort there is the GenericContract
which can be used for calling arbitrary functions on arbitrary contracts.
Obtaining the execution results of the functions on the wrapped contracts is done through one of 3 methods on the ChainFacade class
test_invoke()
- does not persist to chain. Costs no gas.invoke()
- does persist to chain. Requires signing and costs gas.estimate_gas()
- does not persist to chain. Costs no gas.
facade = ChainFacade.node_provider_mainnet()
neo = NeoToken()
result = await facade.test_invoke(neo.candidates_registered())
Candidate
— Container for holding consensus candidate voting results.ChainFacade
— The gateway to the network.ContractMethodResult
— A helper class around thescript
(VM opcodes) to be executed which allows to forward the annotated return type(ContractMethodResult[T]
) of the annotated functionf
to a consumer function, without having to actually return an instance ofT
in the implementation off
.GasToken
— Wrapped GAS token contract.GenericContract
— Generic class to call arbitrary methods on a smart contract.InvokeReceipt
— Transaction submission results.NEP11DivisibleContract
— Base class for divisible NFTs.NEP11NonDivisibleContract
— Base class for non-divisible NFTs.NEP17Contract
— Base class for calling NEP-17 compliant smart contracts.NeoToken
— Wrapped NEO token contract.PolicyContract
— Wrapper around the native contract that manages system policies.RoleContract
— Wrapper around the native Role management contract.
neo3.api.wrappers.
Candidate
(
public_key
, votes
)
Container for holding consensus candidate voting results.
address
— NEO address of the candidate.public_key
— public key of the candidate.votes
— number of votes the candidate has.
neo3.api.wrappers.
ChainFacade
(
rpc_host
, receipt_retry_delay=None
, receipt_timeout=None
)
The gateway to the network.
Abstracts away the logic for talking to the data provider (NodeRPC only atm).
add_signer
(
func
,signer
)
— Add aSigner
which will automatically be included when the various invoke functions.estimate_gas
(
f
,signers
)
(int) — Estimate the gas price for calling the contract method.invoke
(
f
,signers
,network_fee
,system_fee
,append_network_fee
,append_system_fee
)
(InvokeReceipt) — Call a contract method and persist results on the chain. Costs GAS.Waits for tx to be included in a block. Automatically post processes the execution results according to the post-processing function off
if present.invoke_fast
(
f
,signers
,network_fee
,system_fee
,append_network_fee
,append_system_fee
)
(UInt256) — Call a contract method and persist results on the chain. Costs GAS.invoke_multi
(
f
,signers
,network_fee
,system_fee
,append_network_fee
,append_system_fee
,_post_processing
)
(Sequence) — Call all contract methods (concatenated) in one go and persist results on the chain. Costs GAS.Waits for tx to be included in a block. Automatically post processes the execution results according to the post-processing function off
if present.invoke_multi_fast
(
f
,signers
,network_fee
,system_fee
,append_network_fee
,append_system_fee
)
(UInt256) — Call all contract methods (concatenated) in one go and persist results on the chain. Costs GAS.Does not wait for tx to be included in a block. Automatically post processes the execution results according to the post-processing function off
if present.invoke_multi_raw
(
f
,signers
,network_fee
,system_fee
,append_network_fee
,append_system_fee
)
(Sequence) — Call all contract methods (concatenated) in one go and persist results on the chain. Costs GAS.Do not wait for tx to be included in a block. Do not post process the execution results according to the post-processing function off
if present.invoke_raw
(
f
,signers
,network_fee
,system_fee
,append_network_fee
,append_system_fee
)
(InvokeReceipt) — Call a contract method and persist results on the chain. Costs GAS.Waits for tx to be included in a block. Does not post processes the execution results.test_invoke
(
f
,signers
)
(ReturnType) — Call a contract method in read-only mode.This does not persist any state on the actual chain and therefore does not require signing or paying GAS.test_invoke_multi
(
f
,signers
)
(Sequence) — Call all contract methods in one go (concurrently) and return the list of results.test_invoke_raw
(
f
,signers
)
(ExecutionResult) — Call a contract method in read-only mode.This does not persist any state on the actual chain and therefore does not require signing or paying GAS. Does not post process the execution results.node_provider_mainnet
(
)
— Create a facade pre-configured to N3 MainNet.node_provider_testnet
(
)
— Create a facade pre-configured to N3 TestNet.
add_signer
(
func
, signer
)
Add a Signer
which will automatically be included when the various invoke functions.
estimate_gas
(
f
, signers=None
)
→ int
Estimate the gas price for calling the contract method.
invoke
(
f
, signers=None
, network_fee=0
, system_fee=0
, append_network_fee=0
, append_system_fee=0
)
Call a contract method and persist results on the chain. Costs GAS.Waits for tx to be included in a block. Automatically post processes the execution results according to the
post-processing function of f
if present.
f
(ContractMethodResult) — function to call.signers
(Optional, optional) — manually set the list of signers.network_fee
(int, optional) — manually set the network fee.system_fee
(int, optional) — manually set the system fee.append_network_fee
(int, optional) — increase the calculated network fee with this amount.append_system_fee
(int, optional) — increase the calculated system fee with this amount.
A transaction receipt. The state
field of the receipt indicates if the transaction script executedsuccessfully. The remaining fields provide additional information such as notifications that happened
in the contract.
invoke_fast()
- does not wait for a receipt.invoke_raw()
- does not wait for a transaction receipt, does not perform post-processing of the execution
results.
invoke_fast
(
f
, signers=None
, network_fee=0
, system_fee=0
, append_network_fee=0
, append_system_fee=0
)
Call a contract method and persist results on the chain. Costs GAS.
f
(ContractMethodResult) — function to call.signers
(Optional, optional) — manually set the list of signers.network_fee
(int, optional) — manually set the network fee.system_fee
(int, optional) — manually set the system fee.append_network_fee
(int, optional) — increase the calculated network fee with this amount.append_system_fee
(int, optional) — increase the calculated system fee with this amount.
a transaction ID if accepted by the network. Acceptance is does not guarantee successful execution.Acceptance means there are no transaction format errors. Use invoke()
to wait for a receipt. The state
field of the receipt indicates if the transaction script executed successfully.
invoke()
- waits for a transaction receipt, performs post-processing of the execution results.invoke_raw()
- does not wait for a transaction receipt, does not perform post-processing of the execution
results.
invoke_multi
(
f
, signers=None
, network_fee=0
, system_fee=0
, append_network_fee=0
, append_system_fee=0
, _post_processing=True
)
Call all contract methods (concatenated) in one go and persist results on the chain. Costs GAS.Waits for tx to be included in a block. Automatically post processes the execution results according to the
post-processing function of f
if present.
f
(list) — list of functions to call.signers
(Optional, optional) — manually set the list of signers.network_fee
(int, optional) — manually set the network fee.system_fee
(int, optional) — manually set the system fee.append_network_fee
(int, optional) — increase the calculated network fee with this amount.append_system_fee
(int, optional) — increase the calculated system fee with this amount.
a list with the results of all exected functions.
test_invoke_multi
- free equivalent for read only operations or testing.invoke_multi_fast
- does not wait for a receipt.
invoke_multi_raw
- does not wait for a transaction receipt, does not perform post-processing of the
execution results.
invoke_multi_fast
(
f
, signers=None
, network_fee=0
, system_fee=0
, append_network_fee=0
, append_system_fee=0
)
Call all contract methods (concatenated) in one go and persist results on the chain. Costs GAS.Does not wait for tx to be included in a block. Automatically post processes the execution results according to
the post-processing function of f
if present.
f
(list) — list of functions to call.signers
(Optional, optional) — manually set the list of signers.network_fee
(int, optional) — manually set the network fee.system_fee
(int, optional) — manually set the system fee.append_network_fee
(int, optional) — increase the calculated network fee with this amount.append_system_fee
(int, optional) — increase the calculated system fee with this amount.
a transaction ID if accepted by the network. Acceptance is does not guarantee successful execution.Acceptance means there are no transaction format errors. Use invoke()
to wait for a receipt. The state
field of the receipt indicates if the transaction script executed successfully.
test_invoke_fast
- free equivalent for read only operations or testing.invoke_multi
- waits for a transaction receipt, performs post-processing of the execution results.
invoke_multi_raw
- does not wait for a transaction receipt, does not perform post-processing of the
execution results.
invoke_multi_raw
(
f
, signers=None
, network_fee=0
, system_fee=0
, append_network_fee=0
, append_system_fee=0
)
Call all contract methods (concatenated) in one go and persist results on the chain. Costs GAS.Do not wait for tx to be included in a block. Do not post process the execution results according to
the post-processing function of f
if present.
f
(list) — list of functions to call.signers
(Optional, optional) — manually set the list of signers.network_fee
(int, optional) — manually set the network fee.system_fee
(int, optional) — manually set the system fee.append_network_fee
(int, optional) — increase the calculated network fee with this amount.append_system_fee
(int, optional) — increase the calculated system fee with this amount.
a list with the results of all exected functions.
test_invoke_raw
- free equivalent for read only operations or testing.invoke_multi
- waits for a transaction receipt, performs post-processing of the execution results.
invoke_multi_fast
- does not wait for a receipt.
invoke_raw
(
f
, signers=None
, network_fee=0
, system_fee=0
, append_network_fee=0
, append_system_fee=0
)
Call a contract method and persist results on the chain. Costs GAS.Waits for tx to be included in a block. Does not post processes the execution results.
f
(ContractMethodResult) — function to call.signers
(Optional, optional) — manually set the list of signers.network_fee
(int, optional) — manually set the network fee.system_fee
(int, optional) — manually set the system fee.append_network_fee
(int, optional) — increase the calculated network fee with this amount.append_system_fee
(int, optional) — increase the calculated system fee with this amount.
A transaction receipt. The state
field of the receipt indicates if the transaction script executedsuccessfully. The remaining fields provide additional information such as notifications that happened
in the contract.
invoke()
- waits for a transaction receipt, performs post-processing of the execution resultsinvoke_fast()
- does not wait for a receipt.
node_provider_mainnet
(
)
Create a facade pre-configured to N3 MainNet.
node_provider_testnet
(
)
Create a facade pre-configured to N3 TestNet.
test_invoke
(
f
, signers=None
)
→ ReturnType
Call a contract method in read-only mode.This does not persist any state on the actual chain and therefore does not require signing or paying GAS.
f
(ContractMethodResult) — function to call.signers
(Optional, optional) — manually set the list of signers.
invoke()
- persists state.
test_invoke_multi
(
f
, signers=None
)
→ Sequence
Call all contract methods in one go (concurrently) and return the list of results.
f
(list) — list of functions to call.signers
(Optional, optional) — manually set the list of signers.
invoke_multi()
- persists state.
test_invoke_raw
(
f
, signers=None
)
→ ExecutionResult
Call a contract method in read-only mode.This does not persist any state on the actual chain and therefore does not require signing or paying GAS. Does not post process the execution results.
f
(ContractMethodResult) — function to call.signers
(Optional, optional) — manually set the list of signers.
invoke_raw()
- persists state.
neo3.api.wrappers.
ContractMethodResult
(
script
, execution_processor=None
, return_count=1
)
A helper class around the script
(VM opcodes) to be executed which allows to forward the annotated return type(ContractMethodResult[T]
) of the annotated function f
to a consumer function, without having to actually return
an instance of T
in the implementation of f
.
Example: def get_name() -> ContractMethodResult[str]: script = vm.ScriptBuilder().emit_contract_call(some_hash, "name") return ContractMethodResult(script, unwrap.as_str)
def consumer(f: ContractMethodResult[ReturnType]) -> ReturnType:
res = rpc.invoke_script(f.script)
return f.execution_processor(res) # unwraps the result as a string
x = consumer(get_name())
type(x) # str
__init_subclass__
(
*args
,**kwargs
)
— This method is called when a class is subclassed.__class_getitem__
(
cls
,params
)
— Parameterizes a generic class.
__class_getitem__
(
cls
, params
)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method
does. For example, for some generic class Foo
, this is called when we
do Foo[int]
- there, with cls=Foo
and params=int
.
However, note that this method is also called when defining generic
classes in the first place with class Foo(Generic[T]): ...
.
__init_subclass__
(
*args
, **kwargs
)
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
neo3.api.wrappers.
DesignateRole
(
)
Special role that can be assigned to nodes in the network by the consensus committee.
NEO_FS_ALPHABET_NODE
(int) — 0x10ORACLE
(int) — 0x8STATE_VALIDATOR
(int) — 0x4
neo3.api.wrappers.
GasToken
(
)
Wrapped GAS token contract.
balance_of
(
account
)
(ContractMethodResult) — Get the balance for the given account.balance_of_friendly
(
account
)
(ContractMethodResult) — Get the balance for the given account while taking the token decimals into account.call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.decimals
(
)
(ContractMethodResult) — Get the amount of decimals.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.symbol
(
)
(ContractMethodResult) — User-friendly name of the token.total_supply
(
)
(ContractMethodResult) — Get the total token supply in the NEO system.transfer
(
source
,destination
,amount
,data
)
(ContractMethodResult) — Transferamount
of tokens fromsource
account todestination
account.Forwarddata
toonNEP17Payment
handler if applicable.transfer_friendly
(
source
,destination
,amount
,data
)
— Transferamount
of tokens fromsource
account todestination
account.transfer_multi
(
source
,destinations
,amount
,data
,abort_on_failure
)
(ContractMethodResult) — Transferamount
of tokens fromsource
to each account indestinations
.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
balance_of
(
account
)
→ ContractMethodResult
Get the balance for the given account.
Note
The returned value does not take the token decimals into account. e.g. for the GAS token you want to de the result by 10**8 (as the Gas token has 8 decimals).
ValueError
— ifaccount
is an invalid NeoAddress format.
balance_of_friendly
(
account
)
→ ContractMethodResult
Get the balance for the given account while taking the token decimals into account.
Uses the token decimals to convert to the user end representation.
ValueError
— ifaccount
is an invalid NeoAddress format.
transfer
(
source
, destination
, amount
, data=None
)
Transfer amount
of tokens from source
account to destination
account.Forward data
to onNEP17Payment
handler if applicable.
For this to pass while using test_invoke()
, make sure to add a Signer with a script hash equal to the source
account. i.e.
source = <source_script_hash>
signer = verification.Signer(source, payloads.WitnessScope.CALLED_BY_ENTRY)
await facade.test_invoke(token.transfer(source, destination, 10), signers=[signer]))
ValueError
— ifsource
ordestination
is an invalid NeoAddress format
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
transfer_friendly
(
source
, destination
, amount
, data=None
)
Transfer amount
of tokens from source
account to destination
account.
Same as transfer
but does not require manually convert amount if the token uses decimals.
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
ValueError
— ifsource
ordestination
is an invalid NeoAddress format
transfer_multi
(
source
, destinations
, amount
, data=None
, abort_on_failure=False
)
Transfer amount
of tokens from source
to each account in destinations
.
source
(neo3.core.types.uint.uint160 | str) — account to take funds from.destinations
(Sequence) — accounts to send funds to.amount
(int) — how much to transfer.data
(Union, optional) — forward toonNEP17Payment
handler if applicable.abort_on_failure
(bool, optional) — if True aborts the whole transaction if any of the transfers fails.
ValueError
— if any of the destinations is supplied as NeoAddress but is an invalid address format.
The return value after invoking with invoke()
or test_invoke()
is True
if all transfers are successful.
False
otherwise.
decimals
(
)
→ ContractMethodResult
Get the amount of decimals.
Use this with the result of balance_of to display the correct user representation.
symbol
(
)
→ ContractMethodResult
User-friendly name of the token.
total_supply
(
)
→ ContractMethodResult
Get the total token supply in the NEO system.
neo3.api.wrappers.
GenericContract
(
contract_hash
)
Generic class to call arbitrary methods on a smart contract.
call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
neo3.api.wrappers.
InvokeReceipt
(
tx_hash
, included_in_block
, confirmations
, gas_consumed
, state
, exception
, notifications
, result
)
Transaction submission results.
tx_hash
(UInt256) — Unique identifier.included_in_block
(int) — The block height/index the transaction is included in.confirmations
(int) — Number of blocks after accepting the transaction.gas_consumed
(int) — The total gas cost for block inclusion and script execution.state
(VMState) — HALT = success, Others = failure.exception
(Optional) — Virtual Machine exception.notifications
(list) — Smart contract notifications.result
(ReturnType) — Script excution result.
confirmations
(int) — Number of blocks after accepting the transaction.exception
(Optional) — Virtual Machine exception.gas_consumed
(int) — The total gas cost for block inclusion and script execution.included_in_block
(int) — The block height/index the transaction is included in.notifications
(list) — Smart contract notifications.result
(ReturnType) — Script excution result.state
(VMState) — HALT = success, Others = failure.tx_hash
(UInt256) — Unique identifier.
__init_subclass__
(
*args
,**kwargs
)
— This method is called when a class is subclassed.__class_getitem__
(
cls
,params
)
— Parameterizes a generic class.
__class_getitem__
(
cls
, params
)
Parameterizes a generic class.
At least, parameterizing a generic class is the main thing this method
does. For example, for some generic class Foo
, this is called when we
do Foo[int]
- there, with cls=Foo
and params=int
.
However, note that this method is also called when defining generic
classes in the first place with class Foo(Generic[T]): ...
.
__init_subclass__
(
*args
, **kwargs
)
This method is called when a class is subclassed.
The default implementation does nothing. It may be overridden to extend subclasses.
neo3.api.wrappers.
NEP11DivisibleContract
(
contract_hash
)
Base class for divisible NFTs.
The NEP-11 ownerOf
method is named owners_of
in this wrapper.
balance_of
(
owner
,token_id
)
(ContractMethodResult) — Get the token balance for the given owner.balance_of_friendly
(
owner
,token_id
)
(ContractMethodResult) — Get the balance for the given account and convert the result into the user representation.call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.decimals
(
)
(ContractMethodResult) — Get the amount of decimals.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.owners_of
(
token_id
)
(ContractMethodResult) — Get a list of account script hashes that own a part oftoken_id
.properties
(
token_id
)
(ContractMethodResult) — Get all properties for the given NFT.symbol
(
)
(ContractMethodResult) — User-friendly name of the token.token_ids_owned_by
(
owner
)
(ContractMethodResult) — Get an iterator containing all token ids owned by the specified address.tokens
(
limit
,start_index
)
(ContractMethodResult) — Get all tokens minted by the contract.tokens_count
(
)
— Count all tokens minted by the contracttotal_owned_by
(
owner
)
(ContractMethodResult) — Get the total amount of NFTs owned for the given account.total_supply
(
)
(ContractMethodResult) — Get the total token supply in the NEO system.transfer
(
source
,destination
,amount
,token_id
,data
)
(ContractMethodResult) — Transferamount
oftoken_id
fromsource
account todestination
account.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
balance_of
(
owner
, token_id
)
→ ContractMethodResult
Get the token balance for the given owner.
ValueError
— ifowner
is an invalid NeoAddress format.
balance_of_friendly
(
owner
, token_id
)
→ ContractMethodResult
Get the balance for the given account and convert the result into the user representation.
Uses the token decimals to convert to the user end representation.
ValueError
— ifowner
is an invalid NeoAddress format.
owners_of
(
token_id
)
→ ContractMethodResult
Get a list of account script hashes that own a part of token_id
.
transfer
(
source
, destination
, amount
, token_id
, data=None
)
Transfer amount
of token_id
from source
account to destination
account.
For this to pass while using test_invoke()
, make sure to add a Signer with a script hash equal to the source
account. i.e.
source = <source_script_hash>
signer = verification.Signer(source, payloads.WitnessScope.CALLED_BY_ENTRY)
await facade.test_invoke(token.transfer(source, destination, 10), signers=[signer]))
ValueError
— ifsource
ordestination
is an invalid NeoAddress format.
True if token fractions transferred successful. False otherwise.
decimals
(
)
→ ContractMethodResult
Get the amount of decimals.
A zero return value indicates a non-divisible NFT. A bigger than zero return value indicates a divisible NFTs.
properties
(
token_id
)
→ ContractMethodResult
Get all properties for the given NFT.
Note
This is an optional method and may not exist on the contract.
token_ids_owned_by
(
owner
)
→ ContractMethodResult
Get an iterator containing all token ids owned by the specified address.
ValueError
— ifowner
is an invalid NeoAddress format.
tokens
(
limit=2000
, start_index=0
)
→ ContractMethodResult
Get all tokens minted by the contract.
limit: the maximum tokens to return. start_index: where to start collecting results from (see Note1)
Note1:
There is a limit on the returned items in the virtual machine (default: 2048) to avoid too
much compute being used. The limit here is set slightly lower on purpose to allow other necessary items in the
VM. If the contract returns more than 2000 items you need to call the method again providing the start_index
parameter. The tokens_count
method can be used to get the size of the iterator.
Note2: This is an optional method in the NEP-11 standard and can thus fail.
tokens_count
(
)
Count all tokens minted by the contract
Note
This depends on the optional tokens
method and can thus fail.
total_owned_by
(
owner
)
→ ContractMethodResult
Get the total amount of NFTs owned for the given account.
ValueError
— ifowner
is an invalid NeoAddress format.
symbol
(
)
→ ContractMethodResult
User-friendly name of the token.
total_supply
(
)
→ ContractMethodResult
Get the total token supply in the NEO system.
neo3.api.wrappers.
NEP11NonDivisibleContract
(
contract_hash
)
Base class for non-divisible NFTs.
call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.decimals
(
)
(ContractMethodResult) — Get the amount of decimals.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.owner_of
(
token_id
)
(ContractMethodResult) — Get the owner of the given token.properties
(
token_id
)
(ContractMethodResult) — Get all properties for the given NFT.symbol
(
)
(ContractMethodResult) — User-friendly name of the token.token_ids_owned_by
(
owner
)
(ContractMethodResult) — Get an iterator containing all token ids owned by the specified address.tokens
(
limit
,start_index
)
(ContractMethodResult) — Get all tokens minted by the contract.tokens_count
(
)
— Count all tokens minted by the contracttotal_owned_by
(
owner
)
(ContractMethodResult) — Get the total amount of NFTs owned for the given account.total_supply
(
)
(ContractMethodResult) — Get the total token supply in the NEO system.transfer
(
destination
,token_id
,data
)
(ContractMethodResult) — Transfertoken_id
todestination
account.The source account will be the account that pays for the fees (a.k.a. the transaction.sender).transfer_multi
(
destinations
,token_ids
,data
,abort_on_failure
)
(ContractMethodResult) — Transfer multiple token_ids to multiple destinations. Destination and token_ids are paired in order.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
owner_of
(
token_id
)
→ ContractMethodResult
Get the owner of the given token.
transfer
(
destination
, token_id
, data=None
)
Transfer token_id
to destination
account.The source account will be the account that pays for the fees (a.k.a. the transaction.sender).
For this to pass while using test_invoke()
, make sure to add a Signer with a script hash equal to the source
account. i.e.
signer = verification.Signer(source_account, payloads.WitnessScope.CALLED_BY_ENTRY)
await facade.test_invoke(token.transfer(destination, token_id, 10), signers=[signer]))
ValueError
— ifdestination
is an invalid NeoAddress format.
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
transfer_multi
(
destinations
, token_ids
, data=None
, abort_on_failure=False
)
Transfer multiple token_ids to multiple destinations. Destination and token_ids are paired in order.
destinations
(Sequence) — accounts to send tokens to.token_ids
(list) — list of token ids.data
(Union, optional) — forward toonNEP17Payment
handler if applicable.abort_on_failure
(bool, optional) — ifTrue
aborts the whole transaction if any of the transfers fails.
ValueError
— if any of the destinations is supplied as NeoAddress but is an invalid address format.
The return value after invoking with invoke()
or test_invoke()
is True
if all transfers are successful.
False
otherwise.
decimals
(
)
→ ContractMethodResult
Get the amount of decimals.
A zero return value indicates a non-divisible NFT. A bigger than zero return value indicates a divisible NFTs.
properties
(
token_id
)
→ ContractMethodResult
Get all properties for the given NFT.
Note
This is an optional method and may not exist on the contract.
token_ids_owned_by
(
owner
)
→ ContractMethodResult
Get an iterator containing all token ids owned by the specified address.
ValueError
— ifowner
is an invalid NeoAddress format.
tokens
(
limit=2000
, start_index=0
)
→ ContractMethodResult
Get all tokens minted by the contract.
limit: the maximum tokens to return. start_index: where to start collecting results from (see Note1)
Note1:
There is a limit on the returned items in the virtual machine (default: 2048) to avoid too
much compute being used. The limit here is set slightly lower on purpose to allow other necessary items in the
VM. If the contract returns more than 2000 items you need to call the method again providing the start_index
parameter. The tokens_count
method can be used to get the size of the iterator.
Note2: This is an optional method in the NEP-11 standard and can thus fail.
tokens_count
(
)
Count all tokens minted by the contract
Note
This depends on the optional tokens
method and can thus fail.
total_owned_by
(
owner
)
→ ContractMethodResult
Get the total amount of NFTs owned for the given account.
ValueError
— ifowner
is an invalid NeoAddress format.
symbol
(
)
→ ContractMethodResult
User-friendly name of the token.
total_supply
(
)
→ ContractMethodResult
Get the total token supply in the NEO system.
neo3.api.wrappers.
NEP17Contract
(
contract_hash
)
Base class for calling NEP-17 compliant smart contracts.
balance_of
(
account
)
(ContractMethodResult) — Get the balance for the given account.balance_of_friendly
(
account
)
(ContractMethodResult) — Get the balance for the given account while taking the token decimals into account.call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.decimals
(
)
(ContractMethodResult) — Get the amount of decimals.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.symbol
(
)
(ContractMethodResult) — User-friendly name of the token.total_supply
(
)
(ContractMethodResult) — Get the total token supply in the NEO system.transfer
(
source
,destination
,amount
,data
)
(ContractMethodResult) — Transferamount
of tokens fromsource
account todestination
account.Forwarddata
toonNEP17Payment
handler if applicable.transfer_friendly
(
source
,destination
,amount
,data
)
— Transferamount
of tokens fromsource
account todestination
account.transfer_multi
(
source
,destinations
,amount
,data
,abort_on_failure
)
(ContractMethodResult) — Transferamount
of tokens fromsource
to each account indestinations
.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
balance_of
(
account
)
→ ContractMethodResult
Get the balance for the given account.
Note
The returned value does not take the token decimals into account. e.g. for the GAS token you want to de the result by 10**8 (as the Gas token has 8 decimals).
ValueError
— ifaccount
is an invalid NeoAddress format.
balance_of_friendly
(
account
)
→ ContractMethodResult
Get the balance for the given account while taking the token decimals into account.
Uses the token decimals to convert to the user end representation.
ValueError
— ifaccount
is an invalid NeoAddress format.
transfer
(
source
, destination
, amount
, data=None
)
Transfer amount
of tokens from source
account to destination
account.Forward data
to onNEP17Payment
handler if applicable.
For this to pass while using test_invoke()
, make sure to add a Signer with a script hash equal to the source
account. i.e.
source = <source_script_hash>
signer = verification.Signer(source, payloads.WitnessScope.CALLED_BY_ENTRY)
await facade.test_invoke(token.transfer(source, destination, 10), signers=[signer]))
ValueError
— ifsource
ordestination
is an invalid NeoAddress format
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
transfer_friendly
(
source
, destination
, amount
, data=None
)
Transfer amount
of tokens from source
account to destination
account.
Same as transfer
but does not require manually convert amount if the token uses decimals.
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
ValueError
— ifsource
ordestination
is an invalid NeoAddress format
transfer_multi
(
source
, destinations
, amount
, data=None
, abort_on_failure=False
)
Transfer amount
of tokens from source
to each account in destinations
.
source
(neo3.core.types.uint.uint160 | str) — account to take funds from.destinations
(Sequence) — accounts to send funds to.amount
(int) — how much to transfer.data
(Union, optional) — forward toonNEP17Payment
handler if applicable.abort_on_failure
(bool, optional) — if True aborts the whole transaction if any of the transfers fails.
ValueError
— if any of the destinations is supplied as NeoAddress but is an invalid address format.
The return value after invoking with invoke()
or test_invoke()
is True
if all transfers are successful.
False
otherwise.
decimals
(
)
→ ContractMethodResult
Get the amount of decimals.
Use this with the result of balance_of to display the correct user representation.
symbol
(
)
→ ContractMethodResult
User-friendly name of the token.
total_supply
(
)
→ ContractMethodResult
Get the total token supply in the NEO system.
neo3.api.wrappers.
NeoToken
(
)
Wrapped NEO token contract.
balance_of
(
account
)
(ContractMethodResult) — Get the balance for the given account.balance_of_friendly
(
account
)
(ContractMethodResult) — Get the balance for the given account while taking the token decimals into account.call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.candidate_register
(
public_key
)
(ContractMethodResult) — Register as a consensus candidate.candidate_registration_price
(
)
(ContractMethodResult) — Get the amount of GAS to pay to register as consensus candidate.candidate_unregister
(
public_key
)
(ContractMethodResult) — Unregister as a consensus candidate.candidate_vote
(
voter
,candidate
)
(ContractMethodResult) — Cast a vote forcandidate
to become a consensus node.candidate_votes
(
candidate
)
(ContractMethodResult) — Get the total vote count forcandidate
.candidates_registered
(
)
(ContractMethodResult) — Get the first 256 registered candidates.decimals
(
)
(ContractMethodResult) — Get the amount of decimals.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.get_gas_per_block
(
)
(ContractMethodResult) — Get the amount of GAS generated in each block.get_unclaimed_gas
(
account
,end
)
(ContractMethodResult) — Get the amount of unclaimed GAS.symbol
(
)
(ContractMethodResult) — User-friendly name of the token.total_supply
(
)
(ContractMethodResult) — Get the total token supply in the NEO system.transfer
(
source
,destination
,amount
,data
)
(ContractMethodResult) — Transferamount
of tokens fromsource
account todestination
account.Forwarddata
toonNEP17Payment
handler if applicable.transfer_friendly
(
source
,destination
,amount
,data
)
— Transferamount
of tokens fromsource
account todestination
account.transfer_multi
(
source
,destinations
,amount
,data
,abort_on_failure
)
(ContractMethodResult) — Transferamount
of tokens fromsource
to each account indestinations
.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
balance_of
(
account
)
→ ContractMethodResult
Get the balance for the given account.
Note
The returned value does not take the token decimals into account. e.g. for the GAS token you want to de the result by 10**8 (as the Gas token has 8 decimals).
ValueError
— ifaccount
is an invalid NeoAddress format.
balance_of_friendly
(
account
)
→ ContractMethodResult
Get the balance for the given account while taking the token decimals into account.
Uses the token decimals to convert to the user end representation.
ValueError
— ifaccount
is an invalid NeoAddress format.
transfer
(
source
, destination
, amount
, data=None
)
Transfer amount
of tokens from source
account to destination
account.Forward data
to onNEP17Payment
handler if applicable.
For this to pass while using test_invoke()
, make sure to add a Signer with a script hash equal to the source
account. i.e.
source = <source_script_hash>
signer = verification.Signer(source, payloads.WitnessScope.CALLED_BY_ENTRY)
await facade.test_invoke(token.transfer(source, destination, 10), signers=[signer]))
ValueError
— ifsource
ordestination
is an invalid NeoAddress format
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
transfer_friendly
(
source
, destination
, amount
, data=None
)
Transfer amount
of tokens from source
account to destination
account.
Same as transfer
but does not require manually convert amount if the token uses decimals.
The return value after invoking with invoke()
or test_invoke()
is True
if the token transferred successful.
False
otherwise.
ValueError
— ifsource
ordestination
is an invalid NeoAddress format
transfer_multi
(
source
, destinations
, amount
, data=None
, abort_on_failure=False
)
Transfer amount
of tokens from source
to each account in destinations
.
source
(neo3.core.types.uint.uint160 | str) — account to take funds from.destinations
(Sequence) — accounts to send funds to.amount
(int) — how much to transfer.data
(Union, optional) — forward toonNEP17Payment
handler if applicable.abort_on_failure
(bool, optional) — if True aborts the whole transaction if any of the transfers fails.
ValueError
— if any of the destinations is supplied as NeoAddress but is an invalid address format.
The return value after invoking with invoke()
or test_invoke()
is True
if all transfers are successful.
False
otherwise.
candidate_register
(
public_key
)
Register as a consensus candidate.
Account.public_key
True
if successful. False
otherwise.
candidate_registration_price
(
)
→ ContractMethodResult
Get the amount of GAS to pay to register as consensus candidate.
candidate_unregister
(
public_key
)
Unregister as a consensus candidate.
Account.public_key
True
if successful. False
otherwise.
candidate_vote
(
voter
, candidate
)
Cast a vote for candidate
to become a consensus node.
voter
(neo3.core.types.uint.uint160 | str) — the account to vote from.candidate
(ECPoint) — who to vote on.
ValueError
— ifvoter
is an invalid NeoAddress format.
True
if vote cast successful. False
otherwise.
candidate_votes
(
candidate
)
→ ContractMethodResult
Get the total vote count for candidate
.
candidates_registered
(
)
→ ContractMethodResult
Get the first 256 registered candidates.
get_gas_per_block
(
)
→ ContractMethodResult
Get the amount of GAS generated in each block.
get_unclaimed_gas
(
account
, end=None
)
→ ContractMethodResult
Get the amount of unclaimed GAS.
account
(neo3.core.types.uint.uint160 | str) — for whom.end
(Optional, optional) — up to which block height to calculate the GAS bonus. Omit to calculate to the current chain height.
ValueError
— ifaccount
is an invalid NeoAddress format.
decimals
(
)
→ ContractMethodResult
Get the amount of decimals.
Use this with the result of balance_of to display the correct user representation.
symbol
(
)
→ ContractMethodResult
User-friendly name of the token.
total_supply
(
)
→ ContractMethodResult
Get the total token supply in the NEO system.
neo3.api.wrappers.
PolicyContract
(
)
Wrapper around the native contract that manages system policies.
Note
Functions that only consensus committee members can use are not implemented.
call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.exec_fee_factor
(
)
(ContractMethodResult) — The system fee multiplier for transactions.fee_per_byte
(
)
(ContractMethodResult) — The fee per transaction byte.is_blocked
(
script_hash
)
(ContractMethodResult) — Check if an account or contract is blocked on the network.storage_price
(
)
(ContractMethodResult) — The price per byte of smart contract storage.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
exec_fee_factor
(
)
→ ContractMethodResult
The system fee multiplier for transactions.
fee_per_byte
(
)
→ ContractMethodResult
The fee per transaction byte.
is_blocked
(
script_hash
)
→ ContractMethodResult
Check if an account or contract is blocked on the network.
storage_price
(
)
→ ContractMethodResult
The price per byte of smart contract storage.
neo3.api.wrappers.
RoleContract
(
)
Wrapper around the native Role management contract.
call_function
(
name
,args
)
(ContractMethodResult) — Call a method on the contract.destroy
(
destroy_method
)
(ContractMethodResult) — Destroy the contract on chain.get_designated_by_role
(
role
,block_index
)
(ContractMethodResult) — Gets the public keys registered for a given role at a given height.update
(
update_method
,nef
,manifest
,data
)
(ContractMethodResult) — Update this contract on chain with a new manifest and/or contract (NEF).deploy
(
nef
,manifest
,data
)
(ContractMethodResult) — Deploy a smart contract to the chain.
call_function
(
name
, args=None
)
→ ContractMethodResult
Call a method on the contract.
name
— the method name to call as defined in the manifest.args
(Union, optional) — optional list of arguments the function expects.
deploy
(
nef
, manifest
, data=None
)
Deploy a smart contract to the chain.
nef
(NEF) — compiled contract.manifest
(ContractManifest) — contract manifest file.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
contract hash.
destroy
(
destroy_method='destroy'
)
→ ContractMethodResult
Destroy the contract on chain.
This will permanently block the contract hash on the network.
destroy_method
(str, optional) — override with name of the destroy function on the contract. Default signature isdestroy()
.
update
(
update_method='update'
, nef=None
, manifest=None
, data=None
)
→ ContractMethodResult
Update this contract on chain with a new manifest and/or contract (NEF).
Assumes the update method on the contract uses the standard arguments; nef, manifest and (optional) data.
If it uses custom arguments use call_function
instead.
update_method
(str, optional) — override with name of the update function on the contract.nef
(Optional, optional) — compiled contract.manifest
(Optional, optional) — contract manifest.data
(Union, optional) — data that is passed to the_deploy
method of the smart contract (if the method exists).
get_designated_by_role
(
role
, block_index
)
→ ContractMethodResult
Gets the public keys registered for a given role at a given height.