near-encoding
v1.1.4065
Published
npm Package - near-encoding
Readme
near-encoding
Utility functions for encoding, decoding, and interacting with NEAR Protocol smart contracts.
Installation
npm install near-encoding
Usage
Base64 Encoding / Decoding
import { encodeBase64, decodeBase64 } from 'near-encoding';
const encoded = encodeBase64('hello world'); const decoded = decodeBase64(encoded);
Contract Args Encoding / Decoding
import { encodeArgs, decodeArgs } from 'near-encoding';
const encoded = encodeArgs({ key: 'value', count: 42 }); const decoded = decodeArgs(encoded);
View Call (read-only)
import { viewCall } from 'near-encoding';
const result = await viewCall( 'contract.near', 'get_balance', { account_id: 'user.near' } );
Function Call (state-changing)
import { functionCall } from 'near-encoding';
const outcome = await functionCall({ accountId: 'user.near', contractId: 'contract.near', methodName: 'transfer', args: { receiver_id: 'bob.near', amount: '1000' }, gas: '30000000000000', attachedDeposit: '1000000000000000000000000', keyPair: myKeyPair, networkId: 'mainnet', });
API
| Function | Description |
|---|---|
| encodeBase64(input) | Encodes a UTF-8 string to Base64 |
| decodeBase64(input) | Decodes a Base64 string to UTF-8 |
| encodeArgs(args) | JSON-serializes and Base64-encodes an args object |
| decodeArgs(encoded) | Decodes and parses a Base64-encoded args string |
| viewCall(contractId, methodName, args) | Performs a read-only contract call |
| functionCall(opts) | Submits a signed transaction to a NEAR contract |
License
MIT
