Script Builder

To execute code in the blockchain, you need to create a Script, using ScriptBuilder.

First, let's instantiate the ScriptBuilder

import { Address, ScriptBuilder } from "phantasma-sdk-ts"
let scriptBuilder = new ScriptBuilder();

Allow Gas

This method is used to allow a dApp or a wallet to make use some GAS ( KCAL to execute a function that will change something in the blockchain. )

Parameters

  • From: Address or String

  • Target: Address or String, Normally used a Address.Null or a SmartContract Address.

  • GasPrice: Number, Normally used the default Gas Price: 100000

  • GasLimit: Number, This is the max Gas that can be used to execute this transaction.

When you have a AllowGas, you will always need to have a SpendGas

let fromAddress = Address.FromText(Address.NullText); // your address here
let toAddress = Address.FromText(Address.NullText); // your address here
let gasPrice = 100000;
let gasLimit = 210000;
let tokenSymbol = "SOUL";
let amount = 100000000;

It can be used like this.

Spend Gas

This method is used to Spend the Gas a dApp or a wallet to used for the transaction.

Parameters

  • From: Address or String, the Address that will pay for the transaction.

When you have a AllowGas, you will always need to have a SpendGas

An example on how it could be used.

Call Interop

This method is used to Call an Internal Operation in the blockchain, you can check the list of possible Internal Operations that you can call here.

Parameters

  • Method Name: String, Check the list for more details.

  • An array with the arguments needed.

In this example we'll be checking the Runtime.TransferTokens

Call Contract

This method is used to Call a Contract Method that is deployed in the blockchain.

Parameters

  • Contract Name: String

  • Method Name: String, the name of the method inside of the contract.

  • An array with the arguments needed to call that method.

In this example we will be calling the Stake contract the stake Method.

A normal contract will be always lowercased and a Token contract will be always Uppercased.

Example:

  • "stake" -> Stake Contract

  • "SOUL" -> SOUL Token Contract.

Last updated