Developers
  • SWT PROTOCOL
    • Introduction
    • Accounts
    • Transactions
    • Fees
    • Smart Contracts
  • GETTING STARTED
    • Network Node
      • Introduction
      • STEP 1:RENTING A LINUX VPS
      • STEP 2:INSTALLATION OF PUTTY
      • STEP 3:INSTALLATION OF FILEZILLA
      • STEP 4:VPS CONNECTION AND LINUX CONFIGURATION WITH PUTTY (SSH)
      • STEP 5:HOW TO SECURE YOUR VPS
      • STEP 6:USING TMUX THROUGH PUTTY
      • STEP 7:UPLOAD OF THE SWT SOFTWARE WITH FILEZILLA
      • STEP 8:EXTRACT THE SWT SOFTWARE FOLDER
      • STEP 9:RUNNING THE SWT NODE THROUGH TMUX
      • STEP 10:RUNNING THE MONITORING TOOLS
  • API REFERENCE
    • Apache Thrift API
      • Transactions
      • Blocks
      • Smart contract
      • Tokens
      • Wallets
      • Sync info
      • Data structures
    • REST API
      • GetBlocks()
      • GetNodeInfo()
      • GetBalance()
      • GetWalletInfo()
      • GetTokenBalance()
      • GetTransactionsByWallet()
      • GetTransactionInfo()
      • GetEstimatedFee()
      • GetContractByAddress()
      • GetContractFromTransaction()
      • GetContractMethods()
      • ContractValidation()
      • ContractCall()
      • TransactionPack()
      • TransactionExec()
  • SMART CONTRACTS
    • Creating "Hello-world" Smart Contract
    • Smart Contract Methods
    • Smart Contract Standarts
      • Token Smart Contract
      • Escrow Smart Contract
      • Stable coin Token
  • HOW TO REST API
    • Introduction
    • Retrieve a balance from the blockchain
    • Request a specific transaction from the blockchain
    • Sending Transactions to the SWT Blockchain
    • Validating and deploying a Smart Contract with REST API
Powered by GitBook
On this page
  1. SMART CONTRACTS

Smart Contract Methods

sendTransaction

Transfers funds from one wallet address to another, using a specified number of coins. Optional data can be sent to the receiver, as long as the data is formatted using Base58 formatting.

protected final void sendTransaction(String from, String to, double amount, byte... userData)

  • “addressFrom” - address funds are sent from.

  • “addressTo” - address that receives sent funds

  • "amount" - number of transferred funds

  • "userData" - data uploaded by the user

public void sendTransactionExample() {

		return sendTransaction(“addressFrom”, “addressTo”, amount, userData);

	}

invokeExternalContract

Invokes a method from another smart contract:

Object invokeExternalContract(String contractAddress, String method, Object params)

  • "ContractAddress" - is the smart contract address

  • "Method" - is the method that needs to be invoked

  • "Params" - are the smart contract parameters, passed as an object

public void invokeSmartContractMethod()

{

 Object[] params = new Object[] { param1, param2 };

 String resultStr = (String) invokeExternalContract("77GfsQD7peXrxTsjyNVCJmpWWBJAYA9oKy9FGZHb5mJt", "myMethod", params);

}
  • Specify smart contract address, example: tokenKey;

  • Smart contract method, example: myMethod;

  • Specify method parameters, example: Object[] params = new Object[] {param1, param2};

  • Object invokeExternalContract(String contractAddress, String method, Object... params).

getSeed

Generates a random 8 bit number used for development of gambling or gaming dApps.

byte[] getSeed()

public Long getSeedExample() {

		return ByteBuffer.wrap(getSeed()).getLong();

	}

getBalance

Returns the coin balance for a wallet address.

BigDecimal getBalance(String addressBase58)

  • "addressBase58" - the wallet address, in Base58 format

public BigDecimal getBalanceExample() {

		return getBalance(address);

	}

getBlockchainTimeMills

Requests network time in milliseconds

long getBlockchainTimeMills()

long getBlockchainTimeMillsExample() {

        return getBlockchainTimeMills();

    }

payable

This event is invoked when a smart contract receives coins via the Smart Contract Method called "sendTransaction".

String payable(BigDecimal amount, byte[] userData)

This event is triggered within the Smart Contract AFTER the Smart Contract "sendTransaction" method has finalized.

If an exception occurs within this event code, then the "sendTransaction" method fails and no Credits (CS) is transferred and no transaction fees are charged.

String payable(BigDecimal amount, byte[] userData)

{

 string receivedData = userData;

 ...

}
PreviousCreating "Hello-world" Smart ContractNextSmart Contract Standarts

Last updated 1 year ago