npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@okxweb3/coin-near

v1.0.8

Published

Near SDK is used to interact with the Near protocol, it contains the main functions you need when interact with Near Ecosystem.

Downloads

183

Readme

@okxweb3/coin-near

Near SDK is used to interact with the Near protocol, it contains the main functions you need when interact with Near Ecosystem.

Getting Started

Installing Near SDK

npm install @okxweb3/coin-near

What Can Near SDK Do

- getAddress
- validateAddress
- publicKeyFromSeed
- createTransaction
- transfer
- signTransaction
- fullAccessKey

Using Near SDK

Get Address / Validate Address

const seedHex = 'seed hex'
const addr = getAddress(seedHex)

// validate address
const ok = validateAddress(addr)

Transfer

// from, to is account id, not public key
const from = "your_account_id_from.testnet"
const to = "your_account_id_to.testnet"
const seedHex = 'seed hex'
const nonce = 100
// blockHash is from valid blocks within 24 hours
const blockHash = "EekjoegUYx2iibbWDuUSQENYCvUGkxj2Et1hTonbwBuN"

const publicKey = publicKeyFromSeed(seedHex)
const tx = createTransaction(from, publicKey, to, nonce, [], base.fromBase58(blockHash))

const action = transfer(new BN(10).pow(new BN(24)))
tx.actions.push(action)

const [_, signedTx] = await signTransaction(tx, seedHex)
const result = base.toBase64(signedTx.encode())

Create Account

// from, to is account id, not public key
const from = "your_account_id_from.testnet"
const to = "your_account_id_to.testnet"
const seedHex = 'seed hex'
const nonce = 100
// blockHash is from valid blocks within 24 hours
const blockHash = "EekjoegUYx2iibbWDuUSQENYCvUGkxj2Et1hTonbwBuN"

const publicKey = publicKeyFromSeed(seedHex)
const tx = createTransaction(from, publicKey, to, nonce, [], base.fromBase58(blockHash))

const seedHex2 = 'seed hex 2'
const publicKey2 = publicKeyFromSeed(seedHex2)

const action = createAccount()
tx.actions.push(action)
const action2 = addKey(publicKey2, fullAccessKey())
tx.actions.push(action2)

const [_, signedTx] = await signTransaction(tx, seedHex)
const result = base.toBase64(signedTx.encode())

DApp transfer NEAR

let wallet = new NearWallet();
let param: SignTxParams = {
    privateKey: "ed25519:4yNHZKYxR4bk76CZ3MFQxpMeavbPTJVuGNrPZSBp5nzZTc64w35xmrGggbTWLHM1sUJCN5moESgsZKbDVDCj1234",
    data: {
        blockHash: "EekjoegUYx2iibbWDuUSQENYCvUGkxj2Et1hTonbwBuN",
        type: NearTypes.TransferNear,
        nonce: 1,
        "receiverId": "wrap.testnet",
        "amount": "1000000000000000000",
    }
}
let result = await wallet.signTransaction(param)
console.info(result)

DApp transfer ft token

let wallet = new NearWallet();
let param: SignTxParams = {
    privateKey: 'c6a8e5460421b18909798822a56629f0e984b539a06d6020ef7ee7e872d2b391',
    data: {
        blockHash: "EekjoegUYx2iibbWDuUSQENYCvUGkxj2Et1hTonbwBuN",
        type: NearTypes.TransferToken,
        nonce: 1,
        amount: "1000000000000000000",
        receiverId: '316e10e0e93bef0927f4b0bc48849759a42c218b0e81a39ccb8eb15f048b00e8',
        contract: "wrap.near",
        gas: '100000000000000',
        deposit: '1250000000000000000000',
    }
}
let result = await wallet.signTransaction(param)
console.info(result)

Derive Private Key

let wallet = new NearWallet()

let mnemonic = "swift choose erupt agree fragile spider glare spawn suit they solid bus";
let param = {
    mnemonic: mnemonic,
    hdPath: await wallet.getDerivedPath({index:0})
};
let privateKey = await wallet.getDerivedPrivateKey(param);

DApp transaction sign

  let wallet = new NearWallet();
let param: SignTxParams = {
    privateKey: "ed25519:4yNHZKYxR4bk76CZ3MFQxpMeavbPTJVuGNrPZSBp5nzZTc64w35xmrGggbTWLHM1sUJCN5moESgsZKbDVDCj1234",
    data: {
        blockHash: "EekjoegUYx2iibbWDuUSQENYCvUGkxj2Et1hTonbwBuN",
        type: NearTypes.DAppTx,
        nonce: 1,
        "receiverId": "wrap.testnet",
        "actions": [
            {
                "methodName": "near_deposit",
                "args": {},
                "deposit": "10000000000000000000000",
                "gas":"1",
            }
        ]
    }
}
let result = await wallet.signTransaction(param)
console.info(result)

DApp transactions sign

 let wallet = new NearWallet();
        let param: SignTxParams = {
            privateKey: "ed25519:4yNHZKYxR4bk76CZ3MFQxpMeavbPTJVuGNrPZSBp5nzZTc64w35xmrGggbTWLHM1sUJCN5moESgsZKbDVDCj1234",
            data: {
                blockHash: "EekjoegUYx2iibbWDuUSQENYCvUGkxj2Et1hTonbwBuN",
                type: NearTypes.DAppTxs,
                nonce: 1,
                transactions:[{
                    "receiverId": "wrap.testnet",
                    "actions": [
                        {
                            "methodName": "near_deposit",
                            "args": {},
                            "deposit": "10000000000000000000000"
                        }
                    ]
                }]
            }
        }
        let result = await wallet.signTransaction(param)
        console.info(result)

signMessage

const message = "log me in";
const nonce = Buffer.from(Array.from(Array(32).keys()));
const recipient = "http://localhost:3000";
const callbackUrl = "http://localhost:1234";

let wallet = new NearWallet()
let privateKey = "";
let res = await wallet.signMessage({
    privateKey: privateKey,
    data: {
        message,
        recipient,
        nonce,
        callbackUrl,
        state: ""
    }
});

License: MIT