Security News
Research
Data Theft Repackaged: A Case Study in Malicious Wrapper Packages on npm
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
tonweb-contract
Advanced tools
This is a sub package of TonWeb.
The idea is to interact with smart contracts as if they were JavaScript objects.
tonweb.Contract is abstract class for all smart contract objects in TonWeb.
tonweb-contract is already included in the main package:
npm install tonweb
import TonWeb from "tonweb";
TonWeb.Contract;
const tonweb = new TonWeb();
tonweb.Contract;
You can use the tonweb-contract separately:
npm install tonweb-contract
import {Contract} from "tonweb-contract"
ABI and json interface of contract not yet invented in TON, so you need extend tonweb.Contract and compose messages to contract yourself.
import {Contract} from 'web3-eth-contract';
export class MyContract extends Contract {
constructor(provider, options) {
options.code = hexToBytes('abcd..');
super(provider, options);
this.method.myMethod = ...
}
// @override
createDataCell() {
}
// @override
createSigningMessage(options) {
}
}
Deployment functionality is implemented in the Contract class, you only need to override createDataCell and createSigningMessage methods.
tonweb.Contract contains several static functions to help compose messages:
Contract.createStateInit
Contract.createInternalMessageHeader
Contract.createExternalMessageHeader
Contract.createCommonMsgInfo
You can see an example of extending Contract class and using these functions in the code tonweb-contract-wallet
/**
* @param provider {HttpProvider}
* @param options {{code?: Uint8Array, address?: Address, wc?: number}}
*/
const contract = new Contract(provider, options)
const address: Address = contract.getAddress();
const deployMethod = contract.deploy(keyPair.secretKey);
const query: Cell = await deployMethod.getQuery(); // get init external message as Cell
await deplotMethod.estimateFee(); // get estimate fee of deploy
await deployMethod.send(); // send init external message to blockchain
contract.methods; // object contains all methods of this smart contract
const myMethod = contract.methods.myMethod(myParams);
const query: Cell = await myMethod.getQuery(); // get external message
await myMethod.estimateFee(); // get estimate fee
await myMethod.send(); // send to blockchain
const myGetMethod = contract.methods.myGetMethod(myParams);
const result = await myGetMethod.call(); // invoke get-method of this smart contract
@rulon and @tolyayanot
FAQs
DEPRECATED, use https://github.com/toncenter/tonweb
We found that tonweb-contract demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Research
The Socket Research Team breaks down a malicious wrapper package that uses obfuscation to harvest credentials and exfiltrate sensitive data.
Research
Security News
Attackers used a malicious npm package typosquatting a popular ESLint plugin to steal sensitive data, execute commands, and exploit developer systems.
Security News
The Ultralytics' PyPI Package was compromised four times in one weekend through GitHub Actions cache poisoning and failure to rotate previously compromised API tokens.