Module neo_builder

Source
Expand description

§Neo Builder Module (v0.1.8)

Advanced tooling for constructing Neo N3 transactions and smart contract scripts.

§Overview

The neo_builder module provides a comprehensive set of utilities for constructing and manipulating Neo N3 transactions and scripts. It offers a flexible API for building various types of transactions, from simple transfers to complex multi-signature contract invocations.

§Key Components

§Transaction Building

  • Transaction Builder: Fluent API for creating and configuring transactions
  • Fee Calculation: Automatic network and system fee calculation
  • Signer Management: Support for multiple transaction signers with different scopes
  • Witness Configuration: Tools for creating and managing transaction witnesses
  • Attribute Handling: Support for transaction attributes

§Script Construction

  • Script Builder: Create VM scripts for contract invocation
  • Opcode Support: Full support for Neo VM opcodes
  • Parameter Handling: Type-safe handling of contract parameters
  • Verification Scripts: Utilities for building signature verification scripts

§Advanced Features

  • Multi-signature Support: Create and work with multi-signature accounts
  • Helper Methods: Convenience methods for common operations
  • Serialization: Serialization utilities for network transmission

§Examples

§Building Transactions and Scripts

use neo3::neo_builder::{ScriptBuilder, Signer, WitnessScope, TransactionSigner};
use neo3::neo_types::{ContractParameter, ScriptHash};
use std::str::FromStr;

fn basic_examples() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Create a simple script builder
    let mut script_builder = ScriptBuilder::new();
    script_builder.push_data("Hello Neo!".as_bytes().to_vec());
    let script = script_builder.to_bytes();
    println!("Script length: {} bytes", script.len());
     
    // 2. Create a transaction signer
    let script_hash = ScriptHash::from_str("0x1234567890123456789012345678901234567890")?;
    let _signer = Signer::TransactionSigner(
        TransactionSigner::new(script_hash, vec![WitnessScope::CalledByEntry])
    );
     
    // 3. Example contract call
    let mut contract_builder = ScriptBuilder::new();
    let gas_token = ScriptHash::from_str("d2a4cff31913016155e38e474a2c06d08be276cf")?;
    contract_builder.contract_call(
        &gas_token,
        "balanceOf",
        &[ContractParameter::h160(&script_hash)],
        None,
    )?;
    let contract_script = contract_builder.to_bytes();
    println!("Contract script length: {} bytes", contract_script.len());
     
    Ok(())
}

Structs§

AccountSigner
Represents an account signer in the NEO blockchain.
ContextItem
ContractParametersContext
ContractSigner
Represents a contract signer in the NEO blockchain.
InteropServiceIter
An iterator over the variants of InteropService
InvocationScript
An invocation script is part of a witness and is simply a sequence of neo-vm instructions.
ScriptBuilder
A builder for constructing Neo smart contract scripts.
ScriptReader
A utility struct for reading and interpreting Neo smart contract scripts.
Transaction
A Neo N3 blockchain transaction.
TransactionBuilder
TransactionSendToken
TransactionSigner
Represents a transaction signer in the NEO blockchain.
VerificationScript
Witness
WitnessRule

Enums§

BuilderError
CallFlags
InteropService
OracleResponseCode
Signer
Represents a signer in the NEO blockchain.
SignerType
Represents the type of signer in the NEO blockchain.
TransactionAttribute
TransactionError
WitnessAction
WitnessCondition
Enum representing the different types of witness conditions that can be used in a smart contract.
WitnessScope

Statics§

GAS_TOKEN_HASH

Traits§

SignerTrait
A trait for common signer operations in the NEO blockchain.
VecValueExtension

Functions§

add
init_logger
pubkey_to_scripthash
Converts a public key to a script hash.
public_keys_to_scripthash
Converts a list of public keys to a script hash using a given threshold.