Justin Hunter
Justin Hunter

Reputation: 98

How to allow users to deploy NEAR protocol smart contract on the frontend?

Getting close to being able to have individual users deploy their own smart contracts from the frontend witn NEAR, but I'm running into an error. First, the code:

const account = await near.account('polluterofminds.testnet');
const res = await axios.get("/api/contract");
  
const contractRaw = res.data;
const uint8 = new Uint8Array(Buffer.from(contractRaw))

const result = await account.deployContract(uint8);
console.log(result);

When doing this, I get the following error:

Error: The transaction contains more then one action, but it was signed with an access key which allows transaction to apply only one specific action. To apply more then one actions TX must be signed with a full access key

No idea how to solve this one. As far as I know my polluterofminds.testnet account has a full access key and I have signed in with that account.

Anyone successfully done this?

Upvotes: 5

Views: 653

Answers (2)

amgando
amgando

Reputation: 1591

Here it is, from an example created a while ago that demonstrates deploying contracts to user accounts as part of a communication protocol

https://github.com/metanear/metanear-web/blob/master/src/Home.js#L96

UPDATE

(addressing comment to this answer)

@JustinHunter there are 2 types of access keys: FullAccess that lets you sign transactions with all 8 supported actions and FunctionCall access keys that only let you sign transactions with one type, the FunctionCall action.

you can see a little more about transactions and actions, keys, etc here:

and a few relevant words about this restriction in this video: https://youtu.be/ZM7TCONx9BI?t=2127

Upvotes: 4

Vlad Frolov
Vlad Frolov

Reputation: 7756

It seems that you use a function-call-only access key to sign the transaction. To (re-)deploy a contract in NEAR Protocol, you have to use a full-access key. The account in question has full-access and function-call-only keys, but you need to check which one is, ultimately, gets used.

account and keys details on polluterofminds.testnet

Upvotes: 1

Related Questions