AElf.Sdk.CSharp

Contents

BoolState type

Namespace

AElf.Sdk.CSharp.State

Summary

Wrapper around boolean values for use in smart contract state.

BytesState type

Namespace

AElf.Sdk.CSharp.State

Summary

Wrapper around byte arrays for use in smart contract state.

CSharpSmartContractContext type

Namespace

AElf.Sdk.CSharp

Summary

Represents the transaction execution context in a smart contract. An instance of this class is present in the base class for smart contracts (Context property). It provides access to properties and methods useful for implementing the logic in smart contracts.

ChainId property

Summary

The chain id of the chain on which the contract is currently running.

CurrentBlockTime property

Summary

The time included in the current blocks header.

CurrentHeight property

Summary

The height of the block that contains the transaction currently executing.

Origin property

Summary

The address of the sender (signer) of the transaction being executed. It’s type is an AElf address. It corresponds to the From field of the transaction. This value never changes, even for nested inline calls. This means that when you access this property in your contract, it’s value will be the entity that created the transaction (user or smart contract through an inline call).

PreviousBlockHash property

Summary

The hash of the block that precedes the current in the blockchain structure.

Self property

Summary

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

Sender property

Summary

The Sender of the transaction that is executing.

StateProvider property

Summary

Provides access to the underlying state provider.

TransactionId property

Summary

The ID of the transaction that’s currently executing.

Variables property

Summary

Provides access to variable of the bridge.

Transaction property

Summary

Including some transaction info.

Call(fromAddress,toAddress,methodName,args) method

Summary

Calls a method on another contract.

Returns

The result of the call.

Parameters

Name

Type

Description

fromAddress

AElf.Types.Address

The address to use as sender.

toAddress

AElf.Types.Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to call.

args

Google.Protobuf.ByteString

The input arguments for calling that method. This is usually generated from the protobuf

definition of the input type

Generic Types

Name

Description

T

The type of the return message.

ConvertHashToInt64(hash,start,end) method

Summary

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

Returns

The 64-bit signed integer.

Parameters

Name

Type

Description

hash

AElf.Types.Hash

The hash.

start

System.Int64

The inclusive lower bound of the number returned.

end

System.Int64

The exclusive upper bound of the number returned. endValue must be greater than or equal to startValue.

Exceptions

Name

Description

System.ArgumentException

startValue is less than 0 or greater than endValue.

ConvertVirtualAddressToContractAddress(virtualAddress) method

Summary

Converts a virtual address to a contract address.

Returns

The converted address.

Parameters

Name

Type

Description

virtualAddress

AElf.Types.Hash

The virtual address that want to convert.

ConvertVirtualAddressToContractAddress(virtualAddress,contractAddress) method

Summary

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

Returns

The converted address.

Parameters

Name

Type

Description

virtualAddress

AElf.Types.Hash

The virtual address that want to convert.

contractAddress

AElf.Types.Address

The contract address.

ConvertVirtualAddressToContractAddressWithContractHashName(

virtualAddress) method

Summary

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

Returns

The converted address.

Parameters

Name

Type

Description

virtualAddress

AElf.Types.Hash

The virtual address that want to convert.

ConvertVirtualAddressToContractAddressWithContractHashName(

virtualAddress,contractAddress) method

Summary

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

Returns

Parameters

Name

Type

Description

virtualAddress

AElf.Types.Hash

The virtual address that want to convert.

contractAddress

AElf.Types.Address

The contract address.

DeployContract(address,registration,name) method

Summary

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

Parameters

Name

Type

Description

address

AElf.Types.Address

The address of new smart contract.

registration

AElf.Types.SmartContractRegistration

The registration of the new smart contract.

name

AElf.Types.Hash

The hash value of the smart contract name.

FireLogEvent(logEvent) method

Summary

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

Parameters

Name

Type

Description

logEvent

AElf.Types.LogEvent

The event to fire.

GenerateId(contractAddress,bytes) method

Summary

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

Returns

The generated hash type id.

Parameters

Name

Type

Description

contractAddress

AElf.Types.Address

The contract address on which the id generation is based.

bytes

System.Collections. Generic.IEnumerable {System.Byte}

The bytes on which the id generation is based.

GetContractAddressByName(hash) method

Summary

It’s sometimes useful to get the address of a system contract. The input is a hash of the system contracts name. These hashes are easily accessible through the constants in the SmartContractConstants.cs file of the C# SDK.

Returns

The address of the system contract.

Parameters

Name

Type

Description

hash

AElf.Types.Hash

The hash of the name.

GetPreviousBlockTransactions() method

Summary

Returns the transaction included in the previous block (previous to the one currently executing).

Returns

A list of transaction.

Parameters

This method has no parameters.

GetRandomHash(fromHash) method

Summary

Gets a random hash based on the input hash.

Returns

Random hash.

Parameters

Name

Type

Description

fromHash

AElf.Types.Hash

Hash.

GetSystemContractNameToAddressMapping() method

Summary

Get the mapping that associates the system contract addresses and their name’s hash.

Returns

The addresses with their hashes.

Parameters

This method has no parameters.

GetZeroSmartContractAddress() method

Summary

This method returns the address of the Genesis contract (smart contract zero) of the current chain.

Returns

The address of the genesis contract.

Parameters

This method has no parameters.

GetZeroSmartContractAddress(chainId) method

Summary

This 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

Name

Type

Description

chainId

System.Int32

The chain’s ID.

LogDebug(func) method

Summary

Application logging - when writing a contract it is useful to be able to log some elements in the applications log file to simplify development. Note that these logs are only visible when the node executing the transaction is build in debug mode.

Parameters

Name

Type

Description

func

System.Func {System.String}

The logic that will be executed for logging purposes.

RecoverPublicKey() method

Summary

Recovers the public key of the transaction Sender.

Returns

A byte array representing the public key.

Parameters

This method has no parameters.

SendInline(toAddress,methodName,args) method

Summary

Sends an inline transaction to another contract.

Parameters

Name

Type

Description

toAddress

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

args

Google.Protobuf .ByteString

The input arguments for calling that method. This is usually generated from the protobuf

definition of the input type.

SendVirtualInline(fromVirtualAddress,toAddress,methodName,args) method

Summary

Sends a virtual inline transaction to another contract.

Parameters

Name

Type

Description

fromVirtualAddress

AElf.Types.Hash

The hash based on which virtual address is generated.

toAddress

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

args

Google.Protobuf .ByteString

The input arguments for calling that method. This is usually generated from the protobuf

definition of the input type.

SendVirtualInline(fromVirtualAddress,toAddress,methodName,args,

logTransaction) method

Summary

Add an overloaded SDK method SendVirtualInline to support automatically firing a LogEvent to log the inline transactions from virtual addresses.

Parameters

Name

Type

Description

fromVirtualAddress

AElf.Types.Hash

The hash based on which virtual address is generated.

toAddress

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

args

Google.Protobuf .ByteString

The input arguments for calling that method. This is usually generated from the protobuf.

logTransaction

System.Boolean

Whether to fire a logEvent to log inline transactions.

definition of the input type.

SendVirtualInlineBySystemContract(fromVirtualAddress,toAddress,

methodName,args) method

Summary

Like SendVirtualInline but the virtual address uses a system smart contract.

Parameters

Name

Type

Description

fromVirtualAddress

AElf.Types.Hash

The hash based on which virtual address is generated. This method is only available to system smart contract.

toAddress

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

args

Google.Protobuf .ByteString

The input arguments for calling that method. This is usually generated from the protobuf.

definition of the input type.

SendVirtualInlineBySystemContract(fromVirtualAddress,toAddress,

methodName,args,logTransaction) method

Summary

Add an overloaded SDK method SendVirtualInlineBySystemContract, like SendVirtualInline, but the virtual address uses a system smart contract.

Parameters

Name

Type

Description

fromVirtualAddress

AElf.Types.Hash

The hash based on which virtual address is generated. This method is only available to system smart contract.

toAddress

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

args

Google.Protobuf .ByteString

The input arguments for calling that method. This is usually generated from the protobuf.

logTransaction

System.Boolean

Whether to fire a logEvent to log inline transactions.

definition of the input type.

UpdateContract(address,registration,name) method

Summary

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

Parameters

Name

Type

Description

address

AElf.Types.Address

The address of smart contract to update.

registration

AElf.Types.SmartContractRegistration

The registration of the smart contract to update.

name

AElf.Types.Hash <#T-AElf-Types-Hash>

The hash value of the smart contract name to update.

ValidateStateSize(obj) method

Summary

Verify that the state size is within the valid value.

Returns

The state.

Parameters

Name

Type

Description

obj

System.Object

The state.

Exceptions

Name

Description

AElf.Kernel.SmartContract.StateOverSizeException

The state size exceeds the limit.

VerifySignature(tx) method

Summary

Returns whether or not the given transaction is well formed and the signature is correct.

Returns

The verification results.

Parameters

Name

Type

Description

tx

AElf.Types.Transaction

The transaction to verify.

CheckContractVersion(previousContractVersion,registration) method

Summary

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

Returns

Name

Type

Description

IsSubsequentVersion

System.Boolean

Whether the contract version is a subsequent version.

Parameters

Name

Type

Description

previousContractVersion

System.String

The previous contract version.

registration

AElf.Types.SmartContractRegistration

The registration of the smart contract to update.

DeploySmartContract(address,registration,name) method

Summary

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

Returns

Name

Type

Description

ContractVersion

System.String

The verison of smart contract to update.

IsSubsequentVersion

System.boolean

Whether the contract version is a subsequent version

Parameters

Name

Type

Description

address

AElf.Types.Address

The address of new smart contract.

name

AElf.Types.Hash

The hash value of the smart contract name.

registration

AElf.Types.SmartContractRegistration

The registration of the smart contract to update.

UpdateSmartContract(address,registration,name,previousContractVersion) method

Summary

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

Returns

Name

Type

Description

ContractVersion

System.String

The verison of smart contract to update.

IsSubsequentVersion

System.Boolean

Whether the contract version is a subsequent version.

Parameters

Name

Type

Description

address

AElf.Types.Address

The address of smart contract to update.

name

AElf.Types.Hash

The hash value of the smart contract name to update.

registration

AElf.Types.SmartContractRegistration

The registration of the smart contract to update.

previousContractVersion

System.String

The previous contract version.

ECVrfVerify(pubKey,alpha,pi,beta) method

Summary

Verify the ECVrf proof.

Returns

The verified result and the VRF hash output.

Parameters

Name

Type

Description

pubKey

byte[]

The public key.

alpha

byte[]

The VRF hash input.

pi

byte[]

The proof to be verified.

beta

byte[]

The VRF hash output.

CSharpSmartContract type

Namespace

AElf.Sdk.CSharp

Summary

This class represents a base class for contracts written in the C# language. The generated code from the protobuf definitions will inherit from this class.

Generic Types

Name

Description

TContractState

Context property

Summary

Represents the transaction execution context in a smart contract. It provides access inside the contract to properties and methods useful for implementing the smart contracts action logic.

State property

Summary

Provides access to the State class instance. TContractState is the type of the state class defined by the contract author.

ContractState type

Namespace

AElf.Sdk.CSharp.State

Summary

Base class for the state class in smart contracts.

Int32State type

Namespace

AElf.Sdk.CSharp.State

Summary

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

Int64State type

Namespace

AElf.Sdk.CSharp.State

Summary

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

MappedState type

Namespace

AElf.Sdk.CSharp.State

Summary

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

Generic Types

Name

Description

TKey

The type of the key.

TEntity

The type of the value.

SingletonState type

Namespace

AElf.Sdk.CSharp.State

Summary

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

SmartContractBridgeContextExtensions type

Namespace

AElf.Sdk.CSharp

Summary

Extension methods that help with the interactions with the smart contract execution context.

Call(context,address,methodName,message) method

Summary

Calls a method on another contract.

Returns

The return value of the call.

Parameters

Name

Type

Description

context

AElf.Kernel.SmartContract. ISmartContractBridgeContext

The virtual address of the system. contract to use as sender.

address

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to call.

message

Google.Protobuf.ByteString

The input arguments for calling that method. This is usually generated from the protobuf

definition of the input type.

Generic Types

Name

Description

T

The return type of the call.

Call(context,address,methodName,message) method

Summary

Calls a method on another contract.

Returns

The result of the call.

Parameters

Name

Type

Description

context

AElf.Sdk.CSharp.CSharpSmartContractContext

An instance of ISmartContractBridgeContext

address

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to call.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

Generic Types

Name

Description

T

The type of the return message.

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

Summary

Calls a method on another contract.

Returns

The result of the call.

Parameters

Name

Type

Description

context

AElf.Sdk.CSharp.CSharpSmartContractContext

An instance of ISmartContractBridgeContext

fromAddress

AElf.Types. Address

The address to use as sender.

toAddressvv

AElf.Types. Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to call.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

Generic Types

Name

Description

T

The type of the return message.

Call(context,address,methodName,message) method

Summary

Calls a method on another contract.

Returns

The result of the call.

Parameters

Name

Type

Description

context

AElf.Sdk.CSharp.CSharpSmartContractContext

An instance of ISmartContractBridgeContext

address

AElf.Types. Address

The address to use as sender.

methodName

System.String

The name of method you want to call.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

Generic Types

Name

Description

T

The type of the return message.

ConvertToByteString(message) method

Summary

Serializes a protobuf message to a protobuf ByteString.

Returns

ByteString.Empty if the message is null

Parameters

Name

Type

Description

message

Google.Protobuf.IMessage

The message to serialize.

ConvertVirtualAddressToContractAddress(this,virtualAddress) method

Summary

Converts a virtual address to a contract address.

Returns

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

virtualAddress

AElf.Types.Hash Address

The virtual address that want to convert.

ConvertVirtualAddressToContractAddressWithContractHashName(this,

virtualAddress) method

Summary

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

Returns

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

virtualAddress

AElf.Types.Hash Address

The virtual address that want to convert.

Fire(context,eventData) method

Summary

Logs an event during the execution of a transaction. The event type is defined in the AElf.CSharp.core project.

Parameters

Name

Type

Description

context

AElf.Sdk.CSharp.CSharpSmartContractContext

An instance of ISmartContractBridgeContext

eventData

The event to log.

Generic Types

Name

Description

T

The type of the event.

GenerateId(this,bytes) method

Summary

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

Returns

The generated hash type id.

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

bytes

System.Collections.Generic .IEnumerable{System.Byte}

The bytes on which the id generation is based.

GenerateId(this,token) method

Summary

Generate a hash type id based on the currently running contract address and the token.

Returns

The generated hash type id.

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

token

System.String

The token on which the id generation is based.

GenerateId(this,token) method

Summary

Generate a hash type id based on the currently running contract address and the hash type token.

Returns

The generated hash type id.

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

token

AElf.Types.Hash

The hash type token on which the id generation is based.

GenerateId(this) method

Summary

Generate a hash type id based on the currently running contract address.

Returns

The generated hash type id.

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

GenerateId(this,address,token) method

Summary

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

Returns

The generated hash type id.

Parameters

Name

Type

Description

this

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

address

AElf.Types.Address

The address on which the id generation is based.

token

AElf.Types.Hash

The hash type token on which the id generation is based.

SendInline(context,toAddress,methodName,message) method

Summary

Sends an inline transaction to another contract.

Parameters

Name

Type

Description

context

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

toAddress

AElf.Types.Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

SendInline(context,toAddress,methodName,message) method

Summary

Sends a virtual inline transaction to another contract.

Parameters

Name

Type

Description

context

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

toAddress

AElf.Types.Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

SendVirtualInline(context,fromVirtualAddress,toAddress,methodName,

message) method

Summary

Sends a virtual inline transaction to another contract.

Parameters

Name

Type

Description

context

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

fromVirtualAddress

AElf.Types.Hash

The virtual address to use as sender.

toAddress

AElf.Types.Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

SendVirtualInline(context,fromVirtualAddress,toAddress,methodName,

message) method

Summary

Sends a virtual inline transaction to another contract.

Parameters

Name

Type

Description

context

AElf.Kernel.SmartContract. ISmartContractBridgeContext

An instance of ISmartContractBridgeContext

fromVirtualAddress

AElf.Types.Hash

The virtual address to use as sender.

toAddress

AElf.Types.Address

The address of the contract you’re seeking to interact with.

methodName

System.String

The name of method you want to invoke.

message

Google.Protobuf.ByteString

The protobuf message that will be the input to the call.

SmartContractConstants type

Namespace

AElf.Sdk.CSharp

Summary

Static class containing the hashes built from the names of the contracts.

StringState type

Namespace

AElf.Sdk.CSharp.State

Summary

Wrapper around string values for use in smart contract state.

UInt32State type

Namespace

AElf.Sdk.CSharp.State

Summary

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

UInt64State type

Namespace

AElf.Sdk.CSharp.State

Summary

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