Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
@zilliqa-js/contract
Advanced tools
Classes for managing Scilla smart contracts on the Zilliqa blockchain.
interface Field {
name: string;
type: string;
}
interface Transition {
name: string;
params: Field[];
}
interface ABI {
name: string;
fields: Field[];
params: Field[];
transitions: Transition[];
}
interface Value {
vname: string;
type: string;
value: string;
}
type Init = Value[];
type State = Value[];
Contracts
A factory class for creating Contract
instances. Useful for managing
Provider
instances set on Contract
s. The factory is mainly used by the
top-level module exported by @zilliqa-js/zilliqa
.
Contracts(provider: Provider, signer?: Wallet): Contracts
Parameters
provider
: Provider
- a Provider
instancesigner
: Wallet
- a Wallet
instance, used for signing transactions.Returns
Contracts
- a Contracts
instance.provider: Provider
signer: Wallet
static getAddressForContract(tx: Transaction): string
Computes the address for a contract deployment by concatenating
senderAddress
and nonce
and hasing the resulting bytes. Note that this
method will not compute an accurate address if the provided nonce
is not up
to date with the actual nonce on the blockchain.
Parameters
tx
: Transaction
- a Transaction
with nonce
and senderAddress
.Returns
at(address: string, abi: ABI, code: string, init?: Init, state?: State): Contract
Constructs a Contract
with the provided parameters. It is recommended that
this method by used only to construct contracts that have already been
deployed.
Parameters
address
: string
- the contract address.abi
: ABI
- the ABI return by scilla-checker
.code
: string
- UTF-8 encoded Scilla smart contract code.init
: Init
(optional) - the initialisation parameters of the smart contract.state
: State
(optional) - the current smart contract state.Returns
Contract
- a Contract
instance.new(code: string, init: Init, abi?: ABI): Contract
Constructs a Contract
with the provided parameters, that is not deployed.
The contract may subsequently be deployed.
Parameters
code
: string
- UTF-8 encoded Scilla smart contract code.init
: Init
- the initialisation parameters of the smart contract.abi
: ABI
(optional) - the ABI return by scilla-checker
.Returns
Contract
- a Contract
instance.Contract(factory: Contracts, code: string, address?: string, abi?: ABI, init?: Init, state?: State): Contracts
A class representing a single smart contract. Allows for deployment and calling the smart contract's transitions. This class is still under development, and its API should, as of now, be considered unstable and a candidate for breaking changes prior to the launch of the Zilliqa main net.
Parameters
factory
: Contracts - the creating factory instance.code
: string
- UTF-8 Scilla smart contract code.address
: string (Optional)init
: any
(Optional) - contract initialisation parameters.state
: any
(Optional) - contract state.Returns
Contract
- a Contract
instance.factory: Contracts
provider: Provider
signer: Wallet
init: Init
abi?: ABI
(Optional)
state?: State
(Optional)
address?: string
(Optional)
code?: string
(Optional)
status: ContractStatus
isInitialised(): boolean
Returns true
if no attempt has been made to deploy the Contract
, or its
status is unknown.
Returns
boolean
isDeployed(): boolean
Returns true
if the contract has been successfully deployed.
Returns
boolean
isRejected(): boolean
Returns true
if the contract deployment attempt was rejected by the network.
Returns
boolean
deploy(gasPrice: BN, gasLimit: BN): Promise<Contract>
Deploys a contract to the blockchain. This method will automatically generate
and sign the underlying Transaction
and broadcast it. The status of the
Contract
may then be ascertained by using isRejected
or isDeployed
, once
the Promise
resolves.
This API is unstable and subject to breaking changes pre-main net
Parameters
gasPrice
: BN
- an instance of BN.js
.gasLimit
: BN
- an instance of BN.js
.Returns
Promise<Contract>
- will be rejected if a network error occurs. A resolved
Promise
does not indicate that the Contract
is deployed, as the
underlying Transaction
may be confirmed by the blockchain but
unsuccessful, due to lack of gas
, and so on.call(transition: string, params: Value[], amount: BN = new BN(0), gasLimit: BN = new BN(1000), gasPrice: BN = new BN(10)): Promise<Transaction>
Calls a transition of the current contract. At the moment, this is a low-level interface for interacting with simple smart contracts.
This API is unstable and subject to breaking changes pre-main net
Parameters
transition
: string
- the exact name of the contract transition to be
invoked. case mattersparams
: Value[]
- JSON-encoded array of transition parameters.amount
: BN
(Optional) - an instance of BN.js
. Default: 0.gasLimit
: BN
(Optional) - an instance of BN.js
. Default: 1000.gasPrice
: BN
(Optional) - an instance of BN.js
. Default: 10.Returns
Promise<Transaction>
- the Transaction that has been signed and broadcast
to the network.getState(): Promise<State>
Queries the blockchain for the smart contract's state. Note that this method will return the entire state of the smart contract. As a result, if you have a large amount of data stored in a smart contract do not use this method on a client. Instead, use a server-side layer to cache and proxy such queries.
This API is temporary and will be subject to breaking changes
Parameters
None
Returns
Promise<State>
- the Contract state.FAQs
Contract-related functionality.
The npm package @zilliqa-js/contract receives a total of 583 weekly downloads. As such, @zilliqa-js/contract popularity was classified as not popular.
We found that @zilliqa-js/contract demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.