
Security News
AI Agent Lands PRs in Major OSS Projects, Targets Maintainers via Cold Outreach
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.
@wpdas/naxios
Advanced tools

Promise based NEAR Contract and NEAR Wallet client for browser. This was designed to facilitate the React integration with NEAR Blockchain and avoid the huge boilerplate of setting up a wallet and contract.
viewUsing npm:
npm install @wpdas/naxios @near-wallet-selector/modal-ui@8.9.1
Using yarn:
yarn add @wpdas/naxios @near-wallet-selector/modal-ui@8.9.1
Import the NEAR Wallet Selector styles. The app needs it to render the Wallet Selector correctly.
import '@near-wallet-selector/modal-ui/styles.css'
It's super easy to get a Wallet and/or Contract API in place all at once. Take a look:
// web3Api.ts
import naxios from '@wpdas/naxios'
const naxiosInstance = new naxios({
rpcNodeUrl: 'https://free.rpc.fastnear.com', // optional
contractId: CONTRACT_ID,
network: 'testnet',
})
/**
* NEAR Wallet API (Must be a single instance)
*/
export const walletApi = naxiosInstance.walletApi()
// Examples of contract API instance usage
/**
* Contract API
* This is going to use default contractId (CONTRACT_ID)
*/
export const contractApi = naxiosInstance.contractApi()
/**
* Another Contract API
*/
export const socialDBcontractApi = naxiosInstance.contractApi({ contractId: 'v1.social08.testnet' })
/**
* Greeting Contract API
*/
export const greetingContractApi = naxiosInstance.contractApi({
contractId: 'dev-1692221685438-15421910364142',
})
You can open up the NEAR Wallet Selector modal by calling signInModal():
import { walletApi } from './web3Api'
walletApi.signInModal()

By default, naxios only uses @near-wallet-selector/my-near-wallet as a means of connecting the wallet. However, you can add other wallet selectors as follows:
npm install @near-wallet-selector/ledger @near-wallet-selector/my-near-wallet
Then, you can start naxius as follows:
import naxios from '@wpdas/naxios'
import { setupMyNearWallet } from '@near-wallet-selector/my-near-wallet'
import { setupLedger } from '@near-wallet-selector/ledger'
const naxiosInstance = new naxios({
contractId: CONTRACT_ID,
network: 'testnet', // or mainnet, localnet
walletSelectorModules: [setupMyNearWallet(), setupLedger()],
})
/**
* NEAR Wallet API (Must be a single instance)
*/
export const walletApi = naxiosInstance.walletApi()
Find out all the NEAR wallet selectors here: NEAR Wallet Selector
view: Make a read-only call to retrieve information from the network. It has the following parameters:
method: Contract's method name.props?: an optional parameter with args for the contract's method.config?: currently, this has only the useCache prop. When useCache is true, this is going to use non-expired cached data instead of calling the contract's method.call: Call a method that changes the contract's state. This is payable. It has the following parameters:
method: Contract's method nameprops?: an optional parameter with args for the contract's method, gas, deposit to be attached and callbackUrl if you want to take the user to a specific page after a transaction succeeds.callMultiple: Call multiple methods that change the contract's state. This is payable and has the following parameters:
transactionsList: A list of Transaction props. You can use buildTransaction(...) to help you outcallbackUrl?: A page to take the user to after all the transactions succeed.accounts: Signed-in Accounts.accountId: Main/first signed-in account ID in the accounts list.contractId: Contract ID.initNear: Initializes a connection to the NEAR blockchain. This is called automatically when there's any contract interaction.network: Current network (testnet, mainnet or localnet).recentlySignedInWallets: Returns ID-s of 5 recently signed in wallets.selectedWalletId: Selected Wallet IdsignInModal: Open up the Signin Wallet Modal.wallet: Wallet instance.walletSelector: WalletSelector instance.Using a view method is free.
import { greetingContractApi } from './web3Api'
// [free]
greetingContractApi.view<string>('get_greeting').then((response) => console.log(response))
You need to pay for every request you make for a call method. This is going to change data and store it within the blockchain.
import { greetingContractApi } from './web3Api'
// Set greeting [payable]
const args: { message: 'Hi there!!!' }
greetingContractApi.call<string | undefined>('set_greeting', args).then((response) => console.log(response || 'done!'))
As well as the call, you will need to pay for every request you make. This is going to change data and store it within the blockchain.
import { buildTransaction } from '@wpdas/naxios'
import { contractApi } from './web3Api'
// Using the default instance's contract
const transactionA = buildTransaction('set_greeting', { args: { greeting: 'Hello my dear!' } })
const transactionB = buildTransaction('set_age', { args: { age: 22 } })
// Using diff contract
const transactionC = buildTransaction('update_state', {
receiverId: 'my-state-contract.testnet',
args: { allowed: true },
})
// Optional
const callbackUrl = 'https://my-page.com/callback-success'
// [payable]
contractApi.callMultiple([transactionA, transactionB, transactionC], callbackUrl).then(() => console.log('Done!'))
There are two kinds of cache systems to be used. They are Memory Cache and Storage Cache.
Memory Cache: will be cleared when the app refreshes, as its data lives in memory only.
Storage Cache: The data will remain even when the browser tab is refreshed. Data is persisted using Local Storage.
When instantiating a cache, you need to provide the expirationTime (in seconds). This is used to know when the cache should be returned instead of making a real contract call. When the cache expires, a real call to the contract is made. Each contract's method has its own time of expiration.
// web3Api.ts
import naxios, { StorageCache } from '@wpdas/naxios'
// ...
/**
* Cached - Greeting Contract API
*/
export const cachedGreetingContractApi = naxiosInstance.contractApi({
contractId: 'dev-1692221685438-15421910364142',
cache: new StorageCache({ expirationTime: 5 * 60 }), // 5 minutes
})
Then, to use cached view, you can just pass the configuration object saying you want to use cached data.
import { cachedGreetingContractApi } from './web3Api'
// Fetch Greetings [free]
const args: {}
const config: { useCache: true }
cachedGreetingContractApi.view<string>('get_greeting', args, config).then((response) => console.log(response))
buildTransactionThe buildTransaction method is useful when you need to build a contract's Transaction body, mainly when you want to make multiple contract calls.
validateNearAddressThis is used to check if an address is a valid NEAR address.
import { validateNearAddress } from '@wpdas/naxios'
console.log(validateNearAddress('fake.near')) // true
console.log(validateNearAddress('fake.nears')) // false
console.log(validateNearAddress('fake.testnet')) // true
console.log(validateNearAddress('fake')) // false
calculateDepositByDataSizeCalculate required deposit for data being stored. (~0.00001N per byte) with a bit extra for buffer
import { calculateDepositByDataSize } from '@wpdas/naxios'
const myData = { age: 22, name: 'user name' }
console.log(calculateDepositByDataSize(myData)) // 0.00087 Near (not yocto NEAR)
Feel free to open issues or pull requests. For major changes, please open an issue first to discuss what you would like to change.
FAQs
Promise based NEAR Contract and NEAR Wallet client for browser
The npm package @wpdas/naxios receives a total of 61 weekly downloads. As such, @wpdas/naxios popularity was classified as not popular.
We found that @wpdas/naxios demonstrated a healthy version release cadence and project activity because the last version was released less than 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
An AI agent is merging PRs into major OSS projects and cold-emailing maintainers to drum up more work.

Research
/Security News
Chrome extension CL Suite by @CLMasters neutralizes 2FA for Facebook and Meta Business accounts while exfiltrating Business Manager contact and analytics data.

Security News
After Matplotlib rejected an AI-written PR, the agent fired back with a blog post, igniting debate over AI contributions and maintainer burden.