Create Contract
Create a smart contract on Arweave
Last updated
Was this helpful?
Create a smart contract on Arweave
Last updated
Was this helpful?
The createContract
function creates a contract based on the input parameters. The contract can be created either on the mainnet
or on a testnet/ local network
for testing purposes.
The function is called as follows:
The following params are available for this function and they must be passed in as an object:
wallet: ArWallet | string
(optional) : The wallet for deploying the contract with. The type ArWallet
basically checks for Arweave wallet of the type JWKInterface
and type String
expects the private key of the Ethereum wallet and if the wallet param is not passed, it falls back to check for a web-based wallet like or . When falling back to a web wallet, an Ethereum Wallet (like Metamask) is triggered since contract functions use bundling by default, which supports EVM web wallets. If this attempt fails, the function will retry with an Arweave Web Wallet (like ArConnect or arweave.app). The wallet key file can be loaded as follows and passed to the wallet param:
initialState: string
: The initial state of information for the contract at the time of deployment in string
format. The initState
file can be passed in directly as a string or read from a file as follows:
contractSource: string | Buffer
: The contract source parameter can either be the source code or a transaction ID to an existing source code. Contract data (logic) read from a file that must be encoded in utf-8
a format that returns a string
. The contract source file can be loaded or it can be a contract source transaction ID as follows:
tags: array
(optional) : Tags can be added to any transaction for ease of indexing and querying. The syntax for adding tags is as follows:
The name
is the key for a given value
that can be used for querying the transaction in the future. By default, the library adds the 'ArweaveKit' : '1.5.1'
tag on the backend to help identify the library and version used to deploy the function.
data: object
(optional): It accepts Content-Type
of the data and the body
of the data so the data can be accessed with the same deployed contract transaction ID making it an atomic asset.
environment: 'local' | 'testnet' | 'mainnet'
: The environment of choice to create the smart contract in. The testnet
is a pseudo-testing environment created on top of the mainnet
with the help of custom tags.
strategy : 'arweave' | 'ethereum' | 'both'
(optional) : The strategy specifies the wallet (Ethereum or Arweave) to be used for contract creation. While the wallet can be determined by the wallet param passed in, it can be beneficial to pass in when using the browser environment. However, by default, the strategy is set to 'both'
and thus tries the function call with Ethereum first and fallback on an Arweave Wallet.
The function call returns the following data:
contractTxId: string
: The contractTxId
is a unique identifier for further interactions with the contract like read and write operations. It is an instance of the contract source that is uploaded on the network.
status: object
: The result
object returns easy to understand information showing the status of the contract deployment. code: 200
and message: 'SUCCESSFUL'
indicate that the contract has been successfully deployed to the network.
evaluationManifest : object
(optional): The evaluation manifest defines rules that must be used when evaluating the contract being deployed. This includes evaluation options as well as any plugins that the contract deployment may need. Read more about and to learn about the available configurations and their uses. Learn more about plugins .
An arlocal
instance must be running on the port 1984
for the function to work with the local environment. To create one, simply run npx arlocal
in the command line. Learn more about arlocal
.
contract: ContractDeploy
: The contract object has relevant transaction IDs for future interactions. Read more about it .