Sign & Send a Transaction
A web application may create an unsigned transaction and request Adena to sign and send the transaction with the connected account via the doContract
method. Upon receiving the request, Adena will prompt the user to approve the transaction.
If the user approves the transaction, Adena will use the user's private key to sign the transaction to create a signed transaction and broadcast it immediately.
Code
adena.DoContract({
tx: {
messages: [
{
type: "string",
value: object
},
// you may add additional messages within the brackets
...
],
memo?: string
},
isNotification?: boolean // default: true
)
Params
message.type
string
"/bank.MsgSend"
for transfers
"/vm.m_call"
for contract calls
"/vm.m_addpkg"
for adding packages
"/vm.m_run"
for simulating transactions
message.value
object
Values (must match the type's format)
memo
string
Transaction memo (tag)
tx
[Transaction Model]
Transaction info
isNotification
boolean
Notification (default: true)
Response
code
number
Account number
status
string
Returns success
or failure
type
string
Response type
message
string
Descriptive message of the result
data
object
Transaction Result Model
Transaction Model
messages[].type
string
"/bank.MsgSend" for transfers "/vm.m_call" for contract calls "/vm.m_addpkg" for adding packages "/vm.m_run" for executing a gno script
messages[].value
object
Values (must match the type's format)
memo
String
Transaction memo (tag)
Transaction Result Model
hash
string
Transaction hash
height
string
Block height
checkTx
object
Only returns on successful transactions
deliverTx
object
Only returns on successful transactions
/bank.MsgSend
/bank.MsgSend
Sample Request
await adena.DoContract(
{
messages: [{
type: "/bank.MsgSend",
value: {
from_address: "g1ffzxha57dh0qgv9ma5v393ur0zexfvp6lsjpae", // your Adena address
to_address: "g122n67es9vzs0rmharsggfr4sdkd45aysnuzf7m", // recipient's address
amount: "5000000ugnot" // sending amount. 1GNOT = 1000000ugnot
}
}],
memo: "12313"
}
)
Sample Response
{
"code": 0,
"status": "success",
"type": "TRANSACTION_SENT",
"message": "The transaction has been successfully sent.",
"data": {
"height": "4027",
"hash": "SWHSwked0XUWk7R7UmW+iD4PgVugok/Pb7fW0Yf86qE=",
"deliverTx": {},
"checkTx": {}
}
}
/vm.m_call
/vm.m_call
Sample Request
await adena.DoContract(
{
messages: [{
type: "/vm.m_call",
value: {
caller: "g1ffzxha57dh0qgv9ma5v393ur0zexfvp6lsjpae", // your Adena address
send: "",
pkg_path: "gno.land/r/demo/foo20", // Gnoland package path
func: "Transfer", // Function name
args: [ // Arguments
"g122n67es9vzs0rmharsggfr4sdkd45aysnuzf7m",
"1"
]
}
}
],
})
Sample Response
{
"code": 0,
"status": "success",
"type": "TRANSACTION_SENT",
"message": "The transaction has been successfully sent.",
"data": {
"height": "4027",
"hash": "SWHSwked0XUWk7R7UmW+iD4PgVugok/Pb7fW0Yf86qE=",
"deliverTx": {},
"checkTx": {}
}
}
/vm.m_addpkg
/vm.m_addpkg
Sample Request
await adena.DoContract({
messages: [{
type: "/vm.m_addpkg",
value: {
creator: "g1ffzxha57dh0qgv9ma5v393ur0zexfvp6lsjpae", // your Adena address
deposit: "1ugnot", // amount of ugnot to deposit in the package (enter a blank or an amount above 1 ugnot)
package: {
name: "hello", // package name
path: "gno.land/r/demo/hello", // package path (cannot be a duplicate from existing paths on Gnoland)
files: [ // a list of files to deploy
{
name: "hello.gno", // file name
body: "package hello\n\nfunc Hello() string {\n\treturn \"Hello() called\"\n}\n\nfunc Render() string {\n\treturn \"Render() called\"\n}", //file contents
}
]
}
}
}],
});
Sample Response
{
"code": 0,
"status": "success",
"type": "TRANSACTION_SENT",
"message": "The transaction has been successfully sent.",
"data": {
"height": "4027",
"hash": "SWHSwked0XUWk7R7UmW+iD4PgVugok/Pb7fW0Yf86qE=",
"deliverTx": {},
"checkTx": {}
}
}
/vm.m_run
/vm.m_run
Sample Request
await adena.DoContract({
messages: [{
type: "/vm.m_run",
value: {
caller: "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5", // your Adena address
send: "", // amount of ugnot to send
package: {
name: "main", // package name
path: "", // msg_run is empty path
files: [
{
name: "main.gno", // file name
body: "package main\n\nfunc main() {\n\tprintln(\"HELLO WORLD\")\n}", // file content (msg_run has main function)
}
]
}
}
}]
});
Sample Response
{
"status": "success",
"data": {
"document": {
"msgs": [
{
"type": "/vm.m_run",
"value": {
"caller": "g1jg8mtutu9khhfwc4nxmuhcpftf0pajdhfvsqf5",
"send": "",
"package": {
"name": "main",
"path": "gno.land/r/demo/main",
"files": [
{
"name": "script.gno",
"body": "package main\n\nfunc Main() {\n\tprintln(\"HELLO WORLD\")\n}"
}
]
}
}
}
],
"fee": {
"amount": [
{
"amount": "1",
"denom": "ugnot"
}
],
"gas": "2000000"
},
"chain_id": "test3",
"memo": "",
"account_number": "3223",
"sequence": "82"
},
"signature": {
"pub_key": {
"type": "tendermint/PubKeySecp256k1",
"value": "A+FhNtsXHjLfSJk1lB8FbiL4mGPjc50Kt81J7EKDnJ2y"
},
"signature": "MYYWRnJ1OL2Q/QQFy7gzVNs2Rt0YrqWT9na1RnZv0+Qel3VCO01OsSiCqfy6O/In80lzNfPi4a/XeM+wB4JV0Q=="
}
},
"code": 0,
"message": "The transaction has been successfully sent.",
"type": "TRANSACTION_SENT"
}
Last updated