logo

aelf SDK C#

#

#

BytesState type#

Namespace: AElf.Sdk.CSharp.State

Wrapper for byte arrays in smart contract state.

CSharpSmartContractContext type#

Namespace: AElf.Sdk.CSharp

Represents the transaction execution context in a smart contract. Available in the base class for smart contracts (Context property). Provides access to properties and methods useful for implementing smart contract logic.

ChainId property#

The chain ID of the chain where the contract runs.

CurrentBlockTime property#

The time included in the current block's header.

CurrentHeight property#

The height of the block containing the currently executing transaction.

Origin property#

The address of the sender (signer) of the transaction. This value is constant, even for nested inline calls. It represents the entity that created the transaction (user or smart contract).

PreviousBlockHash property#

The hash of the block preceding the current one in the blockchain.

Self property#

The address of the contract currently being executed. This changes with every transaction and inline transaction.

Sender property#

The sender of the currently executing transaction.

StateProvider property#

Provides access to the underlying state provider.

TransactionId property#

The ID of the currently executing transaction.

Variables property#

Provides access to variables of the bridge.

Transaction property#

Includes transaction info.

Call(fromAddress, toAddress, methodName, args) method#

Calls a method on another contract.

Returns: The result of the call.

Parameters:

NameTypeDescription
fromAddressAElf.Types.AddressThe address to use as sender.
toAddressAElf.Types.AddressThe address of the contract you’re seeking to interact with.
methodNameSystem.StringThe name of the method you want to call.
argsGoogle.Protobuf.ByteStringThe input arguments for calling that method. This is usually generated from the protobuf definition of the input type.

Generic Types:

NameDescription
TThe type of the return message

ConvertHashToInt64(hash, start, end) method#

Converts the input hash to a 64-bit signed integer.

Returns#

The 64-bit signed integer.

Parameters#

NameTypeDescription
hashAElf.Types.HashThe hash.
startSystem.Int64Inclusive lower bound of the number returned.
endSystem.Int64Exclusive upper bound of the number returned.

Exceptions#

NameDescription
System.ArgumentExceptionstartValue is less than 0 or greater than endValue.

ConvertVirtualAddressToContractAddress(virtualAddress) method#

Converts a virtual address to a contract address.

Returns#

The converted address.

Parameters#

NameTypeDescription
virtualAddressAElf.Types.HashThe virtual address to convert.

ConvertVirtualAddressToContractAddress(virtualAddress, contractAddress) method#

Converts a virtual address to a contract address with the contract address.

Returns#

The converted address.

Parameters#

NameTypeDescription
virtualAddressAElf.Types.HashThe virtual address to convert.
contractAddressAElf.Types.AddressThe contract address.

ConvertVirtualAddressToContractAddressWithContractHashName(virtualAddress) method#

Converts a virtual address to a contract address with the current contract hash name.

Returns#

The converted address.

Parameters#

NameTypeDescription
virtualAddressAElf.Types.HashThe virtual address to convert.

ConvertVirtualAddressToContractAddressWithContractHashName(virtualAddress, contractAddress) method#

Converts a virtual address to a contract address with the contract hash name.

Returns#

The converted address.

Parameters#

NameTypeDescription
virtualAddressAElf.Types.HashThe virtual address to convert.
contractAddressAElf.Types.AddressThe contract address.

DeployContract(address, registration, name) method#

Deploy a new smart contract (only the genesis contract can call it).

Parameters#

NameTypeDescription
addressAElf.Types.AddressThe address of the new smart contract.
registrationAElf.Types.SmartContractRegistrationThe registration of the new smart contract.
nameAElf.Types.HashThe hash value of the smart contract name.

FireLogEvent(logEvent) method#

This method is used to produce logs that can be found in the transaction result after execution.

Parameters#

NameTypeDescription
logEventAElf.Types.LogEventThe event to fire.

GenerateId(contractAddress, bytes) method#

Generate a hash type id based on the contract address and the bytes.

Returns#

The generated hash type id.

Parameters#

NameTypeDescription
contractAddressAElf.Types.AddressThe contract address for id generation.
bytesSystem.Collections.Generic.IEnumerable<Byte>The bytes for id generation.

GetContractAddressByName(hash) method#

Get the address of a system contract by its name hash. These hashes are in the SmartContractConstants.cs file.

Returns#

The address of the system contract.

Parameters#

NameTypeDescription
hashAElf.Types.HashThe hash of the name.

GetPreviousBlockTransactions() method#

Returns the transactions included in the previous block.

Returns#

A list of transactions.

GetRandomHash(fromHash) method#

Gets a random hash based on the input hash.

Returns#

Random hash.

Parameters#

NameTypeDescription
fromHashAElf.Types.HashHash.

GetSystemContractNameToAddressMapping() method#

Get the mapping of system contract addresses to their name hashes.

Returns#

The addresses with their hashes.

GetZeroSmartContractAddress() method#

Returns the address of the Genesis contract (smart contract zero) of the current chain.

Returns#

The address of the genesis contract.

GetZeroSmartContractAddress(chainId) method#

Returns the address of the Genesis contract (smart contract zero) of the specified chain.

Returns#

The address of the genesis contract for the given chain.

Parameters#

NameTypeDescription
chainIdSystem.Int32The chain’s ID.

LogDebug(func) method#

Logs information for debugging. Visible only when the node is in debug mode.

Parameters#

NameTypeDescription
funcSystem.Func<System.String>The logic for logging purposes.

RecoverPublicKey() method#

Recovers the public key of the transaction sender.

Returns#

A byte array representing the public key.

SendInline(toAddress, methodName, args) method#

Sends an inline transaction to another contract.

Parameters#

NameTypeDescription
toAddressAElf.Types.AddressThe address of the contract to interact with.
methodNameSystem.StringThe name of the method to call.
argsGoogle.Protobuf.ByteStringThe input arguments, usually generated from protobuf.

SendVirtualInline(fromVirtualAddress, toAddress, methodName, args) method#

Sends a virtual inline transaction to another contract.

Parameters#

NameTypeDescription
fromVirtualAddressAElf.Types.HashThe hash for generating the virtual address.
toAddressAElf.Types.AddressThe address of the contract to interact with.
methodNameSystem.StringThe name of the method to call.
argsGoogle.Protobuf.ByteStringThe input arguments, usually generated from protobuf.

SendVirtualInline(fromVirtualAddress, toAddress, methodName, args, logTransaction) method#

Sends a virtual inline transaction to another contract and logs the transaction.

Parameters#

NameTypeDescription
fromVirtualAddressAElf.Types.HashThe hash for generating the virtual address.
toAddressAElf.Types.AddressThe address of the contract to interact with.
methodNameSystem.StringThe name of the method to call.
argsGoogle.Protobuf.ByteStringThe input arguments, usually generated from protobuf.
logTransactionSystem.BooleanWhether to log the inline transaction.

SendVirtualInlineBySystemContract(fromVirtualAddress, toAddress, methodName, args) method#

Sends a virtual inline transaction using a system smart contract.

Parameters#

NameTypeDescription
fromVirtualAddressAElf.Types.HashThe hash for generating the virtual address.
toAddressAElf.Types.AddressThe address of the contract to interact with.
methodNameSystem.StringThe name of the method to call.
argsGoogle.Protobuf.ByteStringThe input arguments, usually generated from protobuf.

SendVirtualInlineBySystemContract(fromVirtualAddress, toAddress, methodName, args, logTransaction) method#

Sends a virtual inline transaction using a system smart contract and logs the transaction.

Parameters#

NameTypeDescription
fromVirtualAddressAElf.Types.HashThe hash for generating the virtual address.
toAddressAElf.Types.AddressThe address of the contract to interact with.
methodNameSystem.StringThe name of the method to call.
argsGoogle.Protobuf.ByteStringThe input arguments, usually generated from protobuf.
logTransactionSystem.BooleanWhether to log the inline transaction.

UpdateContract(address, registration, name) method#

Updates a smart contract (only the genesis contract can call it).

Parameters#

NameTypeDescription
addressAElf.Types.AddressThe address of the smart contract.
registrationAElf.Types.SmartContractRegistrationThe registration of the contract.
nameAElf.Types.HashThe hash value of the contract name.

ValidateStateSize(obj) method#

Verifies that the state size is within the valid limit.

Returns#

The state.

Parameters#

NameTypeDescription
objSystem.ObjectThe state.

Exceptions#

NameDescription
AElf.Kernel.SmartContract.StateOverSizeExceptionThe state size exceeds the limit.

VerifySignature(tx) method#

Checks if the transaction is well-formed and the signature is correct.

Returns#

The verification result.

Parameters#

NameTypeDescription
txAElf.Types.TransactionThe transaction to verify.

CheckContractVersion(previousContractVersion, registration) method#

Checks the contract version when updating the contract (only the genesis contract can call it).

Returns#

NameTypeDescription
IsSubsequentVersionSystem.BooleanWhether the contract version is subsequent.

Parameters#

NameTypeDescription
previousContractVersionSystem.StringThe previous contract version.
registrationAElf.Types.SmartContractRegistrationThe registration of the contract.

DeploySmartContract(address, registration, name) method#

Deploys a new smart contract with a version (only the genesis contract can call it).

Returns#

NameTypeDescription
ContractVersionSystem.StringThe version of the smart contract.
IsSubsequentVersionSystem.BooleanWhether the contract version is subsequent.

Parameters#

NameTypeDescription
addressAElf.Types.AddressThe address of the new smart contract.
registrationAElf.Types.SmartContractRegistrationThe registration of the contract.
nameAElf.Types.HashThe hash value of the contract name.

UpdateSmartContract(address, registration, name, previousContractVersion) method#

Updates a smart contract with a version (only the genesis contract can call it).

Returns#

NameTypeDescription
ContractVersionSystem.StringThe version of the smart contract.
IsSubsequentVersionSystem.BooleanWhether the contract version is subsequent.

Parameters#

NameTypeDescription
addressAElf.Types.AddressThe address of the smart contract.
registrationAElf.Types.SmartContractRegistrationThe registration of the contract.
nameAElf.Types.HashThe hash value of the contract name.
previousContractVersionSystem.StringThe previous contract version.

ECVrfVerify(pubKey, alpha, pi, beta) method#

Verifies the ECVrf proof.

Returns#

The verification result and the VRF hash output.

Parameters#

NameTypeDescription
pubKeybyte[]The public key.
alphabyte[]The VRF hash input.
pibyte[]The proof to be verified.
betabyte[]The VRF hash output.

CSharpSmartContract type#

Namespace: AElf.Sdk.CSharp

Base class for contracts written in C#. Generated code from protobuf definitions inherits from this class.

Generic Types#

NameDescription
TContractStateType of the state class defined by the contract author.

Context property#

Represents the transaction execution context in a smart contract. Provides access to properties and methods for implementing the contract logic.

State property#

Provides access to the State class instance.

ContractState type#

Namespace: AElf.Sdk.CSharp.State

Base class for the state class in smart contracts.

Int32State type#

Namespace: AElf.Sdk.CSharp.State

Wrapper around 32-bit integer values for use in smart contract state.

Int64State type#

Namespace: AElf.Sdk.CSharp.State

Wrapper around 64-bit integer values for use in smart contract state.

MappedState type#

Namespace: AElf.Sdk.CSharp.State

Key-value pair data structure used for representing state in contracts.

Generic Types#

NameDescription
TKeyThe type of the key.
TEntityThe type of the value.

SingletonState type#

Namespace: AElf.Sdk.CSharp.State

Represents single values of a given type for use in smart contract state.

SmartContractBridgeContextExtensions type#

Namespace: AElf.Sdk.CSharp

Extension methods to interact with the smart contract execution context.

Call(context, address, methodName, message) method#

Calls a method on another contract.

Returns:#

The result of the call.

Parameters:#

NameTypeDescription
contextAElf.Kernel.SmartContract.ISmartContractBridgeContextThe virtual address to use as sender.
addressAElf.Types.AddressThe contract address to interact with.
methodNameSystem.StringThe name of the method to call.
messageGoogle.Protobuf.ByteStringThe input arguments for the method.

Generic Types:#

NameDescription
TThe return type of the call.

Call(context, address, methodName, message) method#

Calls a method on another contract.

Returns:#

The result of the call.

Parameters:#

NameTypeDescription
contextAElf.Sdk.CSharp.CSharpSmartContractContextAn instance of ISmartContractBridgeContext.
addressAElf.Types.AddressThe contract address to interact with.
methodNameSystem.StringThe name of the method to call.
messageGoogle.Protobuf.ByteStringThe input arguments for the method.

Generic Types:#

NameDescription
TThe return type of the call.

Call(context, fromAddress, toAddress, methodName, message) method#

Calls a method on another contract.

Returns:#

The result of the call.

Parameters:#

NameTypeDescription
contextAElf.Sdk.CSharp.CSharpSmartContractContextAn instance of ISmartContractBridgeContext.
fromAddressAElf.Types.AddressThe address to use as sender.
toAddressAElf.Types.AddressThe contract address to interact with.
methodNameSystem.StringThe name of the method to call.
messageGoogle.Protobuf.ByteStringThe input arguments for the method.

Generic Types:#

NameDescription
TThe return type of the call.

ConvertToByteString(message) method#

Serializes a protobuf message to a ByteString.

Returns:#

ByteString.Empty if the message is null.

Parameters:#

NameTypeDescription
messageGoogle.Protobuf.IMessageThe message to serialize.

ConvertVirtualAddressToContractAddress(this, virtualAddress) method#

Converts a virtual address to a contract address.

Parameters#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
virtualAddressAElf.Types.Hash AddressThe virtual address to convert.

ConvertVirtualAddressToContractAddressWithContractHashName(this, virtualAddress) method#

Converts a virtual address to a contract address with the current contract address.

Parameters:#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
virtualAddressAElf.Types.Hash AddressThe virtual address to convert.

Fire(context, eventData) method#

Logs an event during a transaction.

Parameters:#

NameTypeDescription
contextAElf.Sdk.CSharp.CSharpSmartContractContextAn instance of ISmartContractBridgeContext.
eventDataThe event to log.

Generic Types:#

NameDescription
TThe type of the event.

GenerateId(this, bytes) method#

Generates a hash type ID based on the current contract address and the bytes.

Returns: The generated hash type ID.#

Parameters:#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
bytesSystem.Collections.Generic.IEnumerable{System.Byte}The bytes for ID generation.

GenerateId(this, token) method#

Generates a hash type ID based on the current contract address and the token.

Returns:#

The generated hash type ID.

Parameters:#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
tokenSystem.StringThe token for ID generation.

GenerateId(this, token) method#

Generates a hash type ID based on the current contract address and the hash type token.

Returns: The generated hash type ID.#

Parameters:#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
tokenAElf.Types.HashThe hash type token for ID generation.

GenerateId(this) method#

Generates a hash type ID based on the current contract address.

Returns: The generated hash type ID.#

Parameters:#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.

GenerateId(this, address, token) method#

Generates a hash type ID based on the address and the bytes.

Returns:#

The generated hash type ID.

Parameters:#

NameTypeDescription
thisAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
addressAElf.Types.AddressThe address for ID generation.
tokenAElf.Types.HashThe hash type token for ID generation.

SendInline(context, toAddress, methodName, message) method#

Sends an inline transaction to another contract.

Parameters:#

NameTypeDescription
contextAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
toAddressAElf.Types.AddressThe contract address to interact with.
methodNameSystem.StringThe name of the method to call.
messageGoogle.Protobuf.ByteStringThe input arguments for the method.

SendInline(context, toAddress, methodName, message) method#

Sends a virtual inline transaction to another contract.

Parameters:#

NameTypeDescription
contextAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
toAddressAElf.Types.AddressThe contract address to interact with.
methodNameSystem.StringThe name of the method to call.
messageGoogle.Protobuf.ByteStringThe input arguments for the method.

SendVirtualInline(context, fromVirtualAddress, toAddress, methodName, message) method#

Sends a virtual inline transaction to another contract.

Parameters:#

NameTypeDescription
contextAElf.Kernel.SmartContract.ISmartContractBridgeContextAn instance of ISmartContractBridgeContext.
fromVirtualAddressAElf.Types.HashThe virtual address to use as sender.
toAddressAElf.Types.AddressThe contract address to interact with.
methodNameSystem.StringThe name of the method to call.
messageGoogle.Protobuf.ByteStringThe input arguments for the method.

SmartContractConstants type#

Namespace: AElf.Sdk.CSharp

Static class containing the hashes built from contract names.

StringState type#

Namespace: AElf.Sdk.CSharp.State

Wrapper around string values for use in smart contract state.

UInt32State type#

Namespace: AElf.Sdk.CSharp.State

Wrapper around unsigned 32-bit integer values for use in smart contract state.

UInt64State type#

Namespace: AElf.Sdk.CSharp.State

Wrapper around unsigned 64-bit integer values for use in smart contract state.

Edited on: 16 July 2024 05:54:53 GMT+0