Skip to content

Instantly share code, notes, and snippets.

@vgrichina
Created June 18, 2020 22:28
Show Gist options
  • Save vgrichina/2b6d6e78fba53c89d416c29685453a12 to your computer and use it in GitHub Desktop.
Save vgrichina/2b6d6e78fba53c89d416c29685453a12 to your computer and use it in GitHub Desktop.
How to deploy contract from AssemblyScript

You can do following to allow passing blob into contract without a lot of overhead:

export function setContractToDeploy(): void {
     env.input(0);
     util.read_register(0);
     // ...
}

see: https://github.com/near/near-sdk-as/blob/9b0526c5cb0ea964cf3fa2983c37fba01aaed7c1/assembly/runtime/util.ts#L82 https://github.com/near/near-sdk-as/blob/72464cdfec7ab373b138a6fc3218f6b3a4147edf/assembly/runtime/env/env.ts#L41

Then on the near-api-js side you can do smth like:

const { functionCall } = nearApi.transaction;
await account.signAndSendTransaction(contractId, [functionCall('setContractToDeploy', bufferWithContract)]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment